I made a script that counts the number of times and object collides with it and when it reaches 0, the object is destroyed and later teleported to another location. Here is the script:
var lives = 5;
var spawnPoint : Transform;
var seconds = 2.0;
function OnTriggerEnter(){
(lives) = (lives) - 1;
if((lives) == 0){
Invoke("LiveAgain", (seconds));
gameObject.SetActive(false);
}
}
function LiveAgain() {
gameObject.transform.position = spawnPoint.position;
gameObject.SetActive(true);
}
How could I make it so then the variable “lives” is changed back to it’s original value after spawning again?(For example, if lives was originally ten, I would want it to be 10 after it spawns again at “spawnPoint”)