Quantcast
Channel: Questions in topic: "dontdestroyonload"
Viewing all articles
Browse latest Browse all 416

DontDestroyOnLoad

$
0
0
On the start screen (**first scene**) of my game player can disable sound using checkbox. It's value stored in the variable toggleValue. When I load game (**second scene**) and then load **first scene** again, I can see, that toggle's value is like it was when I launched the game. Can't understand, what's wrong. public Toggle toggle; public bool toggleValue; void Awake() { DontDestroyOnLoad (this); } public void GetToggle() { Debug.Log (toggle.isOn); toggleValue = toggle.isOn; } **Edit1:** **Options.cs (first scene)** private static Options _Instance = null; public Toggle toggle; public bool toggleValue; 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) myOptions.toggleValue = false; else Debug.Log("Options could not be found"); }

Viewing all articles
Browse latest Browse all 416

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>