|
I have my code right here: private var toggleState1 : boolean = false; function OnGUI() { toggleState1 = GUI.Toggle(Rect(430, 210, 100, 30), toggleState1, "Sound on/off"); AudioListener.pause = toggleState1; } It works fine when toggled, but when I go back to my main menu it is untoggled. How can I save that it is toggled in the whole game?
(comments are locked)
|
|
Two options: http://docs.unity3d.com/Documentation/ScriptReference/Object.DontDestroyOnLoad.html This will prevent the gameObject from being destroyed when you change scenes. There is a draw back. If you go back to the scene where this gameobject is placed you can create multiple instances of it. They will also stay persistent throughout the game so you need to place code to check to see if the gameobject already extists. or http://docs.unity3d.com/Documentation/ScriptReference/PlayerPrefs.html This will stay persistent even if you quit the game. Its very easy to use and straight forward. Hope this helps. I want to use DontDestroyOnLoad, but when I use that, the whole button will be loaded in all scenes. I only need if the button is toggled or not. Maybe I should try PlayerPrefs but i'm not sure how to deal with that..
Sep 11 '12 at 09:29 PM
jennes
Got it! thanks!
Sep 19 '12 at 12:28 PM
jennes
(comments are locked)
|
