How do I increment a variable while reloading a scene?
The game I'm working on is a maze game with a random generator. I am trying to increase the size of the maze everytime the player reaches the end. So I have the a script for the end that reloads the stage every time that it is triggered by the Player. How do I continue to do this but also increase the size of the maze every time it goes through.
Answer by joemane22 · Feb 29, 2020 at 03:44 AM
The easiest way is to use PlayerPrefs
https://docs.unity3d.com/ScriptReference/PlayerPrefs.html
You can just use it like so
PlayerPrefs.SetInt("maze size", PlayerPrefs.GetInt("maze size") * 2);
It is saved on disk so that next time you open the game it will be the same, so if you want it to reset on exit make sure to set it to the default when the game exits!
Also make sure to Set before you Get, otherwise, it may through an error.
Your answer
Follow this Question
Related Questions
Gun not reloading properly & time not deducting correctly when below 10 seconds 2 Answers
Random.Range throws StackOverFlow exception in recursion 1 Answer
How could I increment numbers every 1000th of a second? 4 Answers
How to randomly create a tile based maze 0 Answers
Any good procedural generated maze for 2d out there? 0 Answers