In my first scene of my game player can disable sound using checkbox. It’s value stored in the variable toggleValue. When I load second scene I can see, that toggle’s value is like it was when I launched the game.
Options.cs (first scene)
private static Options _Instance = null;
public Toggle toggle;
public bool toggleValue; // need use it in another scene
void Awake () {
if (_Instance == null) {
DontDestroyOnLoad(this);
_Instance = this;
}
else
Destroy (this.gameObject);
}
public void GetToggle() {
toggleValue = toggle.isOn;
}
OptTest.cs (second scene)
Options myOptions;
void Strat() {
myOptions = (Options) GameObject.FindObjectOfType(typeof(Options));
}
void Update() {
if (myOptions != null)
Debug.Log(myOptions.toggleValue); // I need this..
else
Debug.Log("Options could not be found"); // .. but now I have this
}
Can’t understand, why myOptions == null?
Edit1