- Home /
How to make my espawn delay trigger to work more than once.
I put this question up on the unity forum, but got so many different answers that I didn't know what to do. Tried out all of them but none seemed to work like I wanted. Some of them even did so that the script did not work. So I therefor they here since I have had more luck here before.
I have this respawn script that is supposed to delay the player repawn action by 5 seconds after passing -3 in the Y-axis. It is a diving game and so the point is to let the 5 seconds to show the score and so on before respawning back on the diving board. My problem is that the 5 second delay only works once. After the second jump of the board and the player hits -3 in the y-axis the player respawnes emediatly. I therefore need to make the script work everytime. I need the respawn action to be delayed everytime and not just once. Can someone help me please?
I have only been working with scripts for about a month now and I am still pretty wet behind the ears when it comes to unity script.
This is my code atm:
var reSpawnPoint: Transform; var timer : float = 0.0;
function Update ()
{ if(gameObject.transform.position.y < -3){ timer += Time.deltaTime; if(timer>5) gameObject.transform.position = reSpawnPoint.position;
} }
In case that is how your code is formatted within your editor, and not just how you typed it up here; I would recommend utilising indenting and brackets for all if statements, it is easier to read.
See how $$anonymous$$ike did it below. :)
Answer by Mike 3 · Jul 27, 2010 at 12:45 PM
Just need to reset the timer variable to 0:
var reSpawnPoint: Transform; var timer : float = 0.0;
function Update () { if(gameObject.transform.position.y < -3) { timer += Time.deltaTime; if(timer>5) { timer = 0; gameObject.transform.position = reSpawnPoint.position; } } }
Your answer
Follow this Question
Related Questions
Make Arms Move Slow 0 Answers
Reset GUI texture after respawn 1 Answer
die then respawn after couple of secs when touching a ridgid body? 1 Answer
Finding the player that walked into a ray? 1 Answer
Sniper zooming (toggle) 2 Answers