how to check active scene in unity code example
Example 1: unity how to see what scen you are in
void Update()
{
if (SceneManager.GetActiveScene () == SceneManager.GetSceneByName ("scene1"))
{
SceneManager.LoadScene ("scene2");
}
else if (SceneManager.GetActiveScene () == SceneManager.GetSceneByName ("scene2"))
{
SceneManager.LoadScene ("scene1");
}
}
Example 2: unity scene name get
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class GetSceneName : MonoBehavior {
Scene m_Scene;
string sceneName;
private void Start() {
m_Scene = SceneManager.GetActiveScene();
sceneName = m_Scene.name;
}
}