- Home /
How to restart game while keeping changes done? Alternative for Application.loadlevel.
What im trying to do is change the appearance/ skin of player gameobject by the animator controller. When the game is over, a store button appears which is made with ui panel and buttons. I made a script that when you click a buy button from the store it changes the controller animator to the appearence selected. The on click works fine, it changes the controller but the problem comes in when I hit the restart button which uses Application.loadlevel(Application.loadedlevel) to restart the game, it resets my animator to the previous one. Is there away to restart the game while keeping the changes done? I have already tried DontDestroyOnLoad and it seems to not be working, the gameobject stays with animator controller but its in the dead state and is not visible in the Main Camara.
Answer by NeverHopeless · Aug 05, 2015 at 09:59 AM
I would suggest to preserve the game settings by creating session, through Singleton
(create a class say GameSession and make it singleton), and loads setting from this session instead of setting values inside scripts.
For a basic example:
void Start()
{
gameObject.GetComponent<SpriteRenderer>().color = Color.red;
}
instead use like:
void Start()
{
gameObject.GetComponent<SpriteRenderer>().color = GameSession.sharedInstance.currentThemeColor;
}
This way if you changed your session variable, the scene will reload with a new currentThemeColor
.
Thanks for the answer NeverHopeless, singleton sounds good; ill give it a try later.
Answer by GiyomuGames · Aug 05, 2015 at 09:08 AM
Have you considered putting everything at its initial position instead of reloading the level?
How to put everything back to its original position ins$$anonymous$$d of reset the entire scene? @GiyomuGames
You just have to save whatever parameters you need in the Start method of a $$anonymous$$onoBehaviour. Then when you need to reset everything you can call a newly created "ResetEverything" method (there is already a Reset method in $$anonymous$$onoBehaviour if I recall correctly so the name should be different) and reset everything to the value it was at the Start.
Your answer
![](https://koobas.hobune.stream/wayback/20220611234511im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
In-game Shop / Market/ Buying / inventory system? 3 Answers
how to make a shop system 1 Answer
Select a prefab from shop to Player - 2D Game 0 Answers
How can I use 'buy character button'? 1 Answer
Restart Mecanim's Animator controller 3 Answers