- Home /
Question by
mwolff282 · Jan 12, 2013 at 01:50 AM ·
animationjavascriptcharacterwait
How can I tell Unity to wait to do something until after and animation has finished playing?
I have a cube type character that rolls on the screen, each time a key is pressed it roles in the respective direction. I can't seem to figure out how to tell unity to wait until the animation has finished before allowing more keys to be pressed. Here is what I have so far.
#pragma strict
public var W : GameObject;
public var A : GameObject;
public var S : GameObject;
public var D : GameObject;
function Start () {
}
function Update(){
if(Input.GetKeyUp("d")){
animation.Play("Move(D)");
transform.position.x = transform.position.x + 10;
D.active = true;
W.active = false;
A.active = false;
S.active = false;
}
if(Input.GetKeyUp("a")){
animation.Play("Move(A)");
transform.position.x = transform.position.x - 10;
A.active = true;
W.active = false;
S.active = false;
D.active = false;
}
if(Input.GetKeyUp("w")){
animation.Play("Move(W)");
transform.position.z = transform.position.z + 10;
W.active = true;
A.active = false;
S.active = false;
D.active = false;
}
if(Input.GetKeyUp("s")){
animation.Play("Move(S)");
transform.position.z = transform.position.z - 10;
S.active = true;
W.active = false;
A.active = false;
D.active = false;
}
}
Comment
Best Answer
Answer by save · Jan 12, 2013 at 01:59 AM
You can test if the animation is playing, example:
if(Input.GetKeyUp("d") && !animation.IsPlaying("Move(D)"))