- Home /
Or in if statement (not working)
Hello, i want to play my animation when Vertical and Horizontal keys are pressed. But "OR" don't work.
if (Input.GetButton("Vertical") || Input.GetButton("Horizontal")){
anim.SetFloat("Speed", 0.2f);}
'OR' is working properly. Run this code below:
if (Input.GetButton("Vertical") || Input.GetButton("Horizontal")){
Debug.Log("Vertical key press: "+Input.GetButton("Vertical")+ " & Horizontal key press: "+Input.GetButton("Horizontal"));
}
The output prints on the Console as per the key press which means the OR is working properly and the issue is inside the code in your if loop.
Answer by tayloredgames · Jun 05, 2014 at 12:53 PM
HarshadK is right, your OR operator will be firing correctly under the condition the code block provided is all that is in your Script.
Check that the "Speed" Parameter in the Animator you have attached to your animating GameObject has changed to 0.2f. If it has changed based on pressing Horizontal/Vertical inputs then your code block is working.
When i checked Input.GetAxis("Vertical") > 0 my speed varible set to 0.2f and animation start playing. But i need "GetButton"
Your answer

Follow this Question
Related Questions
2D Animation does not start 1 Answer
Conflicting Animator SetTrigger 0 Answers
Animation doesn't play on Input 1 Answer
How do I nest an existing blend tree inside another? 2 Answers
OnCollision2D stopped working 1 Answer