- Home /
Save information on Level Load HELP
Hi there!
I have a problem when I load a new level for my game. I have a settings menu where I can change sound volume, quality etc.
When I, for example, turn the sound off and load the game, it works fine, but if I'm going back to the main menu by using my pause menu, the sound plays as it was before the setting change.
This happens with every setting I change, everything changes back to deffault.
Do you guys have any clue how to fix this problem?
Answer by unitygamer · Oct 21, 2014 at 04:28 PM
1.create a script called settings or whatever
call DontDestroyOnLoad(this) in Start() or Awake()
add volume, quality etc variables to it
parent to an empty GameObject
store or set value through it
or else you could use playerprefs like PlayerPrefs.SetInt("volume ",volumeVariable);
PlayerPrefs.SetInt("quality", qualityvar);
and get it via PlayerPrefs.GetInt("volume", volumeVariable);
Thanks for the answer! I tested around a little bit and tried using static variables ins$$anonymous$$d. That seems to work, but I read that you should avoid using them.
Is it that bad to use them? $$anonymous$$aybe it doesn't make the game slower if I use them for only 3 variables
its ok using 3 static variables
however as you add more ,you could use the ' don't destroy on load' as you dont have to declare a lot of static variables.
btw using playerprefs will save your player's setting for the next gameplay session as well ,so most people use it for playername , quality,volume and all other stuff.
Static variables will have no effect on your game speed. They are perfectly fine for variables that truly are static, like sound volume. They get a bad rep because so many beginners misuse them.
Static variables can also create hidden dependencies in your code. This can be a nightmare if you intend to reuse your code.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Main Menu Problem 0 Answers
OnCollisionEnter called twice 2 Answers
Help! I downloaded Unity, but everytime i open it, it shuts down! How do i fix this?? 0 Answers
Block Placing Script Help 1 Answer