I have a script set up to where if I am walking the walk animation plays and if I sprint the sprint animation starts playing (same with crouching). However when I sprint and then stop sprinting and keep walking the walk animation stops playing and I have to let off w and press it again for the animation to play again. I got the walk animation to start again by using Input.GetKey instead of Input.GetKeyDown but then the sprint animation would not play :-x. How can I change my code so the walk animation will start playing again when I stop sprinting and resume walking without breaking the sprinting animation?
#pragma strict
function OnEnable ()
{
animation.Stop("sprintAnimation");
animation.Stop("walkAnimation");
animation.Stop("crouchAnimation");
}
var walk : float;
var sprint : float;
var crouch : float;
var walkSprint : float;
var walkCrouch : float;
function Start ()
{
walk = 0;
sprint = 0;
crouch = 0;
walkSprint = 0;
walkCrouch = 0;
}
function Update ()
{
if(Input.GetKeyDown("w"))
{
walk = 1;
animation.Play("walkAnimation", PlayMode.StopAll);
}
if(Input.GetKeyDown("left shift"))
{
sprint = 1;
} if(Input.GetKeyDown("left shift") walk == 1)
{
walkSprint = 1;
sprint = 1;
}
if(Input.GetKeyDown("c"))
{
crouch = 1;
} if(Input.GetKeyDown("c") walk == 1)
{
walkCrouch = 1;
crouch = 1;
}
if(walkSprint == 1)
{
animation.Play("sprintAnimation", PlayMode.StopAll);
}
if(walkCrouch == 1)
{
animation.Play("crouchAnimation", PlayMode.StopAll);
}
if(Input.GetKeyUp("w"))
{
walk = 0;
walkSprint = 0;
walkCrouch = 0;
animation.Stop("walkAnimation");
animation.Stop("sprintAnimation");
animation.Stop("crouchAnimation");
}
if(Input.GetKeyUp("left shift"))
{
sprint = 0;
walkSprint = 0;
animation.Stop("sprintAnimation");
} if(Input.GetKeyUp("left shift") walk == 0)
{
sprint = 0;
walkSprint = 0 ;
animation.Stop("sprintAnimation");
animation.Stop("walkAnimation");
}
if(Input.GetKeyUp("c"))
{
crouch = 0;
walkCrouch = 0;
animation.Stop("crouchAnimation");
} if(Input.GetKeyUp("c") walk == 0)
{
crouch = 0;
walkCrouch = 0;
animation.Stop("crouchAnimation");
animation.Stop("walkAnimation");
}
}