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;
}
}