on scene load unity code example
Example 1: unity load scene
using UnityEngine.SceneManagement;
SceneManager.LoadScene("Scene name");
Example 2: load scene unity
using UnityEngine.SceneManagement
public class LoadScene : MonoBehavior
{
public string sceneToLoad = "Level2";
public void Start()
{
SceneManager.LoadScene(sceneToLoad);
}
}
Example 3: unity method on scene loaded
using UnityEngine;
using UnityEngine.SceneManagement;
public class ExampleCode : MonoBehaviour
{
void Awake()
{
Debug.Log("Awake");
}
void OnEnable()
{
Debug.Log("OnEnable called");
SceneManager.sceneLoaded += OnSceneLoaded;
}
void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
Debug.Log("OnSceneLoaded: " + scene.name);
Debug.Log(mode);
}
void Start()
{
Debug.Log("Start");
}
void OnDisable()
{
Debug.Log("OnDisable");
SceneManager.sceneLoaded -= OnSceneLoaded;
}
}