- Home /
Animation just will not play.
Ok first of all this might not be the best code. But i am using a state machine and the walking animation has a boolean parameter. Well i think you will be able to understand when you see the code. But if i press D it will NOT PLAY, but if i press A IT WILL PLAY, but there is literately no difference except for where you put a, i put and and where you put D, i put D. I could NOT find the solution to this because it doesn't look like anyone had this problem.
var animator : Animator;
function Update(){
if(Input.GetKey(KeyCode.D)){
animator.SetBool("Walking", true);
}else{
animator.SetBool("Walking", false);
}
if(Input.GetKey(KeyCode.A)){
animator.SetBool("Walking", true);
}else{
animator.SetBool("Walking", false);
}
}
Answer by Pyrian · May 09, 2014 at 03:16 AM
When you press D, your code is first setting Walking to true - because D is pressed - and then promptly setting it back to false because A is not pressed.
Try:
if(Input.GetKey(KeyCode.A) | Input.GetKey(KeyCode.D)){
animator.SetBool("Walking", true);
}else{
animator.SetBool("Walking", false);
}
Yeah thanks man, i actually tried to do this before but i accidently put a parentheses in the wrong spot so i tried the one above. Thanks for the code. But if you will read this comment can you say why there is only one | ins$$anonymous$$d of two ||, because i watch videos and they use || for and, but here there is only one.
Either would work, but || is probably better than | in this case - and most cases. Sorry. The difference is just whether the second part is evaluated if the first part is already true.
Your answer
![](https://koobas.hobune.stream/wayback/20220613144614im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
2D character animation walk left and right 2 Answers
2D Animation with JavaScript (Android). Help! 0 Answers
2D Animation does not start 1 Answer
When i make my character animated, he can only move up, down left and right (2D) (JS) 0 Answers
2D Sprite animation - How do I jump to the next frame? 0 Answers