x


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

more ▼

asked Jul 07 '11 at 06:59 PM

randombinaries gravatar image

randombinaries
16 7 9 11

When posting code, please format it with the 1010101 button and use proper indentation.

Jul 07 '11 at 10:02 PM Chris D

You need an external master code to handle the switching.

Jul 07 '11 at 10:11 PM Dreamblur
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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

}

more ▼

answered Jul 08 '11 at 04:09 AM

Eli Davis gravatar image

Eli Davis
233 11 14 15

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x572
x379
x237
x29
x13

asked: Jul 07 '11 at 06:59 PM

Seen: 1016 times

Last Updated: Jul 15 '11 at 09:07 PM