I have wrote this script that plays my animations to what keys and buttons are being held down, I have recently added in the walk left and right animations. They do not play when A or D is pressed where as if I put it into a different script and take off the script that has the shooting animations on it works fine. What’s going wrong and how can I fix this?
function Start () {
animation["walk_left"].speed = 1.5;
animation["walk_right"].speed = 1.5;
animation["walk_left"].wrapMode = WrapMode.Loop;
animation["walk_right"].wrapMode = WrapMode.Loop;
animation["idle"].speed = 0.5;
animation["walk"].speed = 2.5;
animation["reload"].speed = 1.5;
animation["shoot"].speed = 6;
animation["idle"].wrapMode = WrapMode.Loop;
animation["walk"].wrapMode = WrapMode.Loop;
animation["shoot"].wrapMode = WrapMode.Once;
animation["reload"].wrapMode = WrapMode.Once;
animation["shoot"].layer = 1;
animation["reload"].layer = 2;
animation.Stop();
}
var fullClip : int = 8 ;
var bulletsLeft : int = 8 ;
function Update () {
if(Mathf.Abs(Input.GetAxis("Vertical")) > 0.1)
animation.CrossFade("walk");
else
animation.CrossFade("idle");
if(Input.GetKeyDown("a")){
animation.CrossFade("walk_left");
}
if(Input.GetKeyDown("d")){
animation.CrossFade("walk_right");
}
if(Input.GetButtonDown("Fire1")){
if(bulletsLeft > 0 ){
bulletsLeft -- ;
animation.Stop();
animation.Play("shoot");
}
}
if(Input.GetButtonDown("r")){
animation.Stop();
animation.CrossFade("reload");
bulletsLeft = fullClip ;
}
}