- Home /
How to make a good options menu.
Hey, so I've been focusing on improving my skills with NGUI and GUI stuff over all. So I thought a good way would be to make a menu. I'm using NGUI and for a while everything went great. I got my game scene to load, quit button and also an options button which brings up a new window with all the options and hides the other window. It al fell apart when I realised I had no idea how to keep the selected options. How could I save the selected options so it would be the same when the game restarts and also when switching scenes. I know I could make a prefab that would save the settings between scenes but could I also use that when quitting the game? Thanks a lot. :)
Answer by nockieboy · Jul 29, 2014 at 03:56 AM
Take a look at playerprefs - http://docs.unity3d.com/ScriptReference/PlayerPrefs.html.
You can basically set an object to be non-destructible, so it survives the loading of the next scene and you can access variables in a script attached to it. Take a look at gameObject.DontDestroyOnLoad:
http://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html.
These should give you some good pointers on how to preserve settings across scenes. :)
Ah great thanks. That's what I was thinking about. Now I just need to figure out a way to keep the settings when quitting the game. :)
PlayerPrefs
are stored when you quit the game - from the docs:
"Stores and accesses player preferences between game sessions."
The tutorial is also a good place to see all the concepts in action.