To Redirect the scene in the unity engine.
Create a new 3D scene in the unity and save it as Level1.
From the Hierarchy , select a plane , cube and a sphere and place in the scene. Scale of plane is (4,1,4) .Scale of Cube is (2,1,2).Scale of sphere is (1,1,1).
Right Click on Assets , choose material and give color to your cube and sphere.
Add rigid body component to cube and sphere.
Select the sphere, in the inspector - select tag and add a new tag named "cube".And tag the cube in sphere inspector.
From File , create another scene and name that scene as "Level2".
Create a C# file named Prog and type the code required to redirecting the scene. And Add the C# file to the cube.
From File, select Build settings and add open scene.Both the scene should be added.
From Hierarchy , Select text and type " YOU WON ", and uncheck the text in inspector.
Slect the cube inspector , add the text object in the WinText feild under the C# file.
Compile and run the program, as a result when the sphere falls on the cube ,it gets disappeared and the text message will pop up on the scene . On clicking "R",the level1 scene will be redirected to Level2 scene.
Developed By : Sowmiya N
Register No : 212221230106
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Prog : MonoBehaviour
{
Rigidbody rb;
public GameObject WinText;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.R))
{
SceneManager.LoadScene("Level2");
}
}
public void OnMouseDown()
{
Destroy(gameObject);
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "cube")
{
Destroy(collision.gameObject);
WinText.SetActive(true);
}
}
}
Thus redirecting a scene is done successfully in the unity engine.