I am working on an endless runner sort of game, in which the player is going to remain stationary while the plane beneath him moves and respawns creating the illusion of movement. My issue is I cannot for the life of me get this object to instantiate only once. After viewing other threads, I’ve tried using a boolean but obviously I’m doing something wrong. I tried writing a collision script also but ended up running into the same issue. Also I tried throwing in some wait time to try and fix it that way. It’s a mess. Here is the code with the boolean:
var respawnquery;
function Start () {
respawnquery = false;
}
function Update () {
transform.position.z -= 1 * Time.deltaTime;
if(!respawnquery)
respawn();
}
function respawn(){
yield WaitForSeconds(6);
Instantiate(gameObject, Vector3(0,0,0), transform.rotation);
respawnquery = true;
}