- Home /
playing a different animation in an array
i have a series of animations of a gear stick and want to cycle through them by pressing a guy button. i have successfully done this with an array of materials but i am struggling to do the same with the animations. below is my attempt at the code. i would be grateful for any help, thank you
var gearIndx : int;
var gears : AnimationClip[];
var car : GameObject;
function OnGUI(){
if(GUI.Button(Rect(10,10,50,50),gearTex)){ gearIndx++;
}
}
function Update(){
car.animation = gears[gearIndx];
}
Answer by Rod-Green · Nov 08, 2011 at 05:02 PM
You need to set the clip and to play the animation.. http://unity3d.com/support/documentation/ScriptReference/Animation.html
car.animation.clip = gears[gearIndx];
car.animation.Play();
Or you can do:
car.animation.Play("clipname", PlayMode.StopAll);
thank you the first example worked. just need to disable my button whilst an animation is playing or it cycles too fast
if (GUI.RepeatButton(Rect(310,10,50,50),gearTex)){ car.animation.clip = gears[gearIndx]; gearIndx++; car.animation.Play(); if (gearIndx == 4){ gearIndx = 0; }
is what i used in the end for anyone viewing this
One thing you could do is..
if(!car.animation.isPlaying)
{
car.animation.clip = gears[gearIndx];
car.animation.Play();
}
Your answer
Follow this Question
Related Questions
Running animation until a certain time/frame 0 Answers
how to index through game objects? 1 Answer
Arrays rebels to my power! 1 Answer
Adding a texture to array textures?! 1 Answer