- Home /
1 Scene game|| Reset variables
Hi, im doing a new game, as the tittle says it has only got one scene, so my question is: Is there anyway i can reset all the variables of a script without calling application.loadLevel(loadedLevel);? Becasuse if I call it, my scene will completly reset and the menu will pop up (And what i want is to restart the level that the player is playing). I think that i should write a function like:
void Update(){
if(dead){Restart();}
}
void Restart(){
score=0;
pos = new vector3();
...
}
But I was wondering is there was something more simple, please enlighten me.
Answer by Stormizin · Sep 10, 2014 at 07:20 PM
Make a function that get all the script variables and give them the default values, or Destroy/Remove the component/object and instantiate again.
I think attributing the variables is the safer way to reach this.
That´s what I thought, but I will try both ways, without a doubt the function one would have better performance so probably I ll end up doing that one as I stated in my first message. The remove/instantiate can be used in some specific cases (small objects) so thank you :)