[Unity](EN) Change scene using code
Environment and Prerequisite
- Unity
- C#
Usage
- Use
LoadScene
inUnityEngine.SceneManagement
using UnityEngine;
using UnityEngine.SceneManagement;
public class ExampleClass : MonoBehaviour
{
void Start()
{
SceneManager.LoadScene("OtherSceneName");
}
}
Example
- Change scene when collision occured
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class MoveCircle : MonoBehaviour
{
private void OnCollisionEnter2D(Collision2D collision)
{
SceneManager.LoadScene("GameOverScene");
}
}