I am rather new to Unity but I haven’t found an answer to my question anywhere.
I have two scenes - 1 and 0.
Scene 0 has a MonoBehaviour script attached to the main camera.
However, when switching back and forth from scene 1 to 0, each time I load scene 0, I get another instance of that script, and it completely ruins my program’s logic. I need this script to function as a singleton.
For information, I am switching scenes using SceneManager.LoadScene:
SceneManager.LoadScene(0);
I have even added inside the scene 0 script, a print command to see the instance ID, and indeed I see two different instances:
void Start()
{
print("Object ID: " + this.GetInstanceID());
done = false;
trajectory = new List<Point>();
position = Vector3.zero;
controller = GetComponent<SteamVR_Behaviour_Pose>();
}
What is causing this? Please help as I am clueless on how to solve this.