Hello. I know in unity you can use toggle buttons. I want to affect which scripts are active in another scene, how can I make it so that when "Toggle Button A" is checked script A will be active when another scene loads? To put that in context, my game will (hopefully) have a wide variaty of options(difficulty, stage layout, mode, player type, etc). Rather than make a separate scene for each possible combination, I want to make each individual option its own script and then just activate it depending on the checked buttons. I hope that makes sense, Thanks.
asked Dec 02 '10 at 04:57 AM
Another way to do it is with PlayerPrefs. In the first scene, you could use PlayerPrefs.SetInt to store whether a script in the next scene will be active or not (so the int will be either 0 or 1), and in the second scene use PlayerPrefs.GetInt to find the value:
Scene 1's script will be something like this:
Then the script in Scene 2 will be something like this:
in terms of the GetComponent(otherScript), the (otherScript) part will be the name of your script controlling the difficulty, and (if you want to use GetComponent) will be attached to the same Game Object as this script.
A good reason to use PlayerPrefs is that you can change the integer to something that's not 0 or 1, so if instead of a single toggle (which'd only be on or off) you can have a GUI toolbar (Easy/Medium/Hard). The scene 2 script would then be like this:
Another (possibly) good reason to use PlayerPrefs is that it persists even when you close the program, so when the player picks their preferences, they won't have to re-do it every time they load the game. Although if you don't want that, you could make a script that resets the preferences at startup.
Hope that helped!
answered Dec 02 '10 at 06:01 AM
You'll need to store the checkbox values on a game object that persists across scene changes then when the scene is loaded enable and disable scripts based on the values.
Should be enough to get you started working with this way of doing it.
answered Dec 02 '10 at 05:46 AM