switching turns between two game objects.

Hi Everyone

Can anyone help me with this problem please. I’ve got this scenario where a game object move forwards and after 26 seconds it respawns back to its original position. Now directly opposite this first game object is a second game object that does the same thing as the first game object. The only problem I have is I want them to take turns moving forward and respawning. So the first one moves forward then respawns & stops moving. The second one then moves forward, respawns & stops moving allowing the first one to move forward. You get the picture the only other thing that I would like to add would be that is would have to be continuous cycle. Here’s my code so far:

var Sec2Respawn : float = 26.0;

function Update(){
    transform.Translate(0, 0, -1 * Time.deltaTime);

    if(Sec2Respawn > 0){
        Sec2Respawn -= Time.deltaTime;
    }

    if(Sec2Respawn <= 0){
        Sec2Respawn = 26.0;
        var parentMill = GameObject.Find("MovementWindMill");
        parentMill.transform.position = Vector3(2.508217, 6.518723, 25.69707);

    }
}

Help much appreciated. Thanks

Heres a method you could consider about using. Feel free modifying it the way you want. comment if you have any questions or problems

var respawnTime : float = 26.0;

var firstObjectEnabled = true;

function Update(){

	var gameObectOne = GameObject.Find("Your game object");
	var gameObectTwo = GameObject.Find("Your other game object");
	
	if(firstObjectEnabled == true){
		if(respawnTime > 0){
			gameObectOne.transform.Translate(0, 0, -1 * Time.deltaTime);
			respawnTime -= Time.deltaTime;
		}

		if(respawnTime <= 0){
			respawnTime = 26.0;
			//reset to position you want
			firstObjectEnabled = false;
		}
	} else {
		if(respawnTime > 0){
			gameObectTwo.transform.Translate(0, 0, -1 * Time.deltaTime);
			respawnTime -= Time.deltaTime;
		}

		if(respawnTime <= 0){
			respawnTime = 26.0;
			//reset to position you want
			firstObjectEnabled = true;
		}		
	}
}