Hi guys, is there a way to keep track of how many lives left have the player?
I have a gameobject, it have a script attached to it, the player interacts with the gameobject. Inside the script I have a method called Check(). Using a event trigger (pointer click) I call that method to check if the player lose a life or wins a point. The gameobject is set up using the Start() method on the script attached to it.
If the player lose a life then I should do something like
lives --;
So if the initial value was 3, now he will have 2 lives left. Then I need to reload the same scene, and here is where my problem begins…
If I set the amount of lives on the Start() method, when the scene reloads the player will have 3 lives again and of course, that should not happen because the player just lost one life before the scene reload.
I could create an empty gameobject and attach a script to it (let’s call it TempScript) with a variable called livesLeft to store there the amount of lives left, and then use the Awake() method and the known
DontDestroyOnLoad(This);
When the scene reloads the variable livesLeft will not change, so if the player had two lives at reload, after the reload he still will have two lives. The problem using this solution is, how do I set up the initial amount of lives then???
Load scene 1st time → livesLeft = 3 → load gameobject → player interact with gameobject → Check() is called → player lose life → livesLeft = livesLeft - 1 → reload scene → livesLeft = 2 → …
I’m sorry, maybe this is a very simple question, but I can’t see a solution…
Yes, I know about singletons, but I really don’t want to use them unless there is no other choice.