questions about animations

I have a question about my game model. Ive made a tank that has animated textures for the treads thats has a script and four wheels that are driven by the animation system.
they both work fine and look good. What i would like to do is stop and start the two animations with the movement keys of the tank. My script for movement is the arrow keys up for forward and down for reverse plus left and right for turning. what is the best way to set this up? do i need one script for both types or two seperate. The four wheels
have seperate animation files.

thank you

wayne

var frontWheel1 : GameObject;
var frontWheel2 : GameObject;
var backWheel1 : GameObject;
var backWheel2 : GameObject;

function Update(){

frontWheel1.animation.Play();
frontWheel2.animation.Play();
backWheel1.animation.Play();
backWheel2.animation.Play();

}

if(Input.GetKey("up")){
  //whatever your moving code is
  frontWheel1.animation["//animation name"].speed = 1;
  frontWheel2.animation["//animation name"].speed = 1;
  backWheel1.animation["//animation name"].speed = 1;
  backWheel2.animation["//animation name"].speed = 1;
]else
  frontWheel1.animation["//animation name"].speed = 0;
  frontWheel2.animation["//animation name"].speed = 0;
  backWheel1.animation["//animation name"].speed = 0;
  backWheel2.animation["//animation name"].speed = 0;
}

if(Input.GetKey("down")){
  //whatever your moving code is
  frontWheel1.animation["//animation name"].speed = -1;
  frontWheel2.animation["//animation name"].speed = -1;
  backWheel1.animation["//animation name"].speed = -1;
  backWheel2.animation["//animation name"].speed = -1;
]else
  frontWheel1.animation["//animation name"].speed = 0;
  frontWheel2.animation["//animation name"].speed = 0;
  backWheel1.animation["//animation name"].speed = 0;
  backWheel2.animation["//animation name"].speed = 0;
}

}

Basically we are starting an stopping the animations whenever the forward key is pressed, whenever the back key is pressed we rewind the animation. You can do all of this with one code.:slight_smile: A better way do this is with a parent controlling all of the children’s animations or to use an array. However, I’m not able to test the script so I made it simple. Let me know if it works. For the wheels to turn left and right just rotate them when ever the keys are pressed. Below is psuedo-code (it won’t actually work):

if(GetKey("left")){
//rotate front wheel 1 and 2 
}else
if(GetKey("right")){
//rotate front wheel 1 and 2 
}else
//return to original position

You should be able to figure this part of it out on your own, best of luck!

is this for a computer or phone?

its for a pc i got a script to work for the tanks bogie wheels they stop and go fine
i need something to make the animated textures on the treads stop and go.
Ive tried a few things but no good.

thank you for your reply i apreciate the feedback

wayne