Hi everybody !
I try to make a script for the animations of my character, where is the error ?
Help me ^^"
#pragma strict
function Start () {
print ("Trying to animate that.");
}
function Update() {
if (Input.GetKeyDown(KeyCode.W)) {
GetComponent.<Animation>().CrossFade("walk_inPlace");
} else if (Input.GetKeyDown(KeyCode.A)) {
GetComponent.<Animation>().CrossFade("run_left");
} else if (Input.GetKeyDown(KeyCode.D)) {
GetComponent.<Animation>().CrossFade("run_right");
} else if (Input.GetKeyDown(KeyCode.S)) {
GetComponent.<Animation>().CrossFade("run_backward");
} else {
GetComponent.<Animation>().CrossFade("idle");
}
}
Thanks !
Try using Input.GetKey instead of Input.GetKeyDown. GetKeyDown only return true the frame the key was first pressed. The next frame it will return false even if the key is held down.
#pragma strict
private var anim : Animation;
function Start () {
anim = GetComponent.<Animation>();
}
function Update() {
if (Input.GetKey(KeyCode.W))
anim.CrossFade("walk_inPlace");
else if (Input.GetKey(KeyCode.A))
anim.CrossFade("run_left");
else if (Input.GetKey(KeyCode.D))
anim.CrossFade("run_right");
else if (Input.GetKey(KeyCode.S))
anim.CrossFade("run_backward");
else
anim.CrossFade("idle");
}