How to update variable based on scene
the "nop" variable is staying at zero and is not updating to equals 1/ What do i do?
using UnityEngine; using System.Collections;
public class masterCode : MonoBehaviour { public playerController pC; private int test; private int nop;
void Awake () {
DontDestroyOnLoad(transform.gameObject);
}
void OnLevelWasLoaded (int index) {
test = index;
switch (index) {
case 0:
nop = 1;
break;
}
}
void Start () {
}
void Update () {
Debug.Log (test);
Debug.Log (nop);
}
}
Does OnLevelWasLoaded trigger correctly? You could try putting one of the Debug.Logs inside it
Are you calling Scene$$anonymous$$anager.LoadScene (or Application.LoadLevel)?
OnLevelWasLoaded will not execute if you're just hitting the play button. You need to specifically load a scene.
yes im using the correct version. And the scene index is loading. But the variable isnt changing? What do i do?
Okay. So the variable actually is being update. But not when i load the second level
I found that the debugger does crazy things when trying to debugging switch case statements, so try change to a if else and put a break point inside to see what happens