Thnx Sycle. U’re right. It Works perfectly. But now it gives me another issue - the walk animation doesn’t work((( Here is a code :
p.s. I’ve corrected the shooting now it works, with possibility to change shooting animation speed.
var animShoot;
function Start ()
{
// Set all animations to loop
animation.wrapMode = WrapMode.Loop;
// except shooting
animation["jump"].wrapMode = WrapMode.Once;
animation["shoot"].wrapMode = WrapMode.Once;
animShoot = animation["shoot"];
animShoot.speed = 0.1;
animation["jump"].layer = 1;
animation["shoot"].layer = 0;
animation.Stop();
}
function Update () {
// Based on the key that is pressed,
// play the walk animation or the idle animation
if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.1)
animation.CrossFade("walk");
if (Input.GetAxis("Vertical") < -0.1)
animation.CrossFade("backWalk");
else
animation.CrossFade("idle");
// Jumping
if (Input.GetButtonDown ("Jump"))
animation.CrossFade("jump");
if (Mathf.Abs(Input.GetAxis("Horizontal")) > 0.1)
animation.CrossFade("leanRight");
// Shooting
}
function FixedUpdate()
{
if (Input.GetButton ("Fire1"))
{
animation.Play("shoot");
animation.CrossFade("walk");
}
}
OMG i’m lame! All what i had to do was to put backwalk after else statement:
function Update () {
// Based on the key that is pressed,
// play the walk animation or the idle animation
if (Input.GetAxis("Vertical") > 0.1)
animation.CrossFade("walk");
else
animation.CrossFade("idle");
if (Input.GetAxis("Vertical") < -0.1)
animation.CrossFade("backWalk");