- Home /
Animation plays on one script but not another
I've been trying to set up some basic 2d top-down controls, and I have a mostly-functioning script for animations. Thing is, it's very messy, so I've been trying to transfer the information into a new script, but the "up" run animation will play for one script but not the other.
This is the old script that works:
// W is pressed, D is not
else if (Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.D))
{
//Move at a 90 degree angle
anim.SetInteger ("RunState", 9);
sprite.flipX = false;
}
and here's the new script, which for the most part is exactly the same but fails to function:
//Up
if (Input.GetKey (KeyCode.W))
{
anim.SetInteger ("Runstate", 9);
sprite.flipX = false;
}
The idle animation works for both scripts when I check either of them in the player component; does anybody know how to solve this?
(P.S I'd eventually like to add to the script that "if W or UpArrow is pressed," etc. But I forgot what the or operator is in Unity. The information would be very helpful; thanks!)
Answer by MaxGuernseyIII · Oct 19, 2017 at 10:06 PM
Off the cuff, I would suggest the fact that your case is different. In the one that doesn't work you use the key "Runstate" instead of "RunState". I can't quickly find a solid ruling on whether that key is case sensitive but there's not a good reason for it to be case insensitive and I can see it being confusing to add case insensitivity. Some poor, misguided soul might also claim that it's faster (in a meaningful way) for it to test for exact matches.
You're a genius, thank you! ^^' I didn't even notice. There's about half a second delay between the key being pressed and the animation playing, and exit transition is turned off, but that helped a ton!
Answer by Ratslayer · Oct 19, 2017 at 10:08 PM
The second version has Run s tate instead of Run S tate. Mechanim parameters are case sensitive.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Mouse move to control the animation 1 Answer
How to start Animation left turn With the cursor 1 Answer
I'm having animation problems 0 Answers