- Home /
Question by
knuckles209cp · Oct 01, 2013 at 04:44 AM ·
animationsprint
Play animation if 2 buttons are held down?
SO i got this script off a question , i dont own it ... but i want it so if im holding down w AND left shift , my sprint animation plays , and if im only holding w then my walk animation plays - its for an FPS game .. OH and also i want the animation to KEEP playing UNTIL i let go of shift and/or w . Thanks guys
if(Input.GetKey(KeyCode.W))
animation.Play();
else if(Input.GetKeyUp(KeyCode.W))
animation.Stop();
Comment
Answer by tw1st3d · Oct 01, 2013 at 04:50 AM
Here, try using a switch setup,
switch(true)
{
case Input.GetKeyDown(KeyCode.W) && Input.GetKeyDown(KeyCode.LeftShift):
// If you've pressed W and LSHIFT
gameObject.animation = runningAnimation;
break;
case Input.GetKeyDown(KeyCode.W):
// If you've pressed W
gameObject.animation = walkingAnimation;
break;
}
It says " unknown identifier "sprintAnimation" and "walkAnimation"
whats a switch setup?
A switch setup is a list of cases that can occur based on the switch. In this case, it's (true), so any of those cases that return true will execute. Are your animations defined somewhere in your script?