- Home /
Pay animation if joystick pushed to left and another if joystick is pushed to right
I have a car setup, sorta similar to Mario Kart, the steering is controlled by and analog stick is it possible to set steering to the left to play my "leftlean" animation and when steering to the right play my "rightlean" animation? I tried this
function Update ()
{
if(Input.GetAxis("Horizontal"))
{
animation.wrapMode = WrapMode.Clamp;
animation.Play("leftlean"); // name of the animation clip
}
}
With no luck, any help?
Answer by JGeorge · Mar 07, 2011 at 02:42 PM
Input.GetAxis("Horizontal") doesn't return a bool. It returns a float, between -1(left) to 1(right). During your if statement on line 3 you could instead check this: if(Input.GetAxis("Horizontal") > 0 || Input.GetAxis("Horizontal") < 0)
This would let you know that the controls had been moved.
Then, if it was greater than 0 you could play your right animation, and vice versa for left.
Answer by negreiros_jorge · Apr 14, 2012 at 04:53 PM
bool InputHor=Input.GetAxis("Horizontal")<0||Input.GetAxis("Horizontal")>0;
Your answer
Follow this Question
Related Questions
Make a cube rotate in right or left direction randomly 3 Answers
Problem with diagonal movement + animations 1 Answer
Joystick Diagonal? 2 Answers
Auto walk 2 Answers
Input controls at run time reset to duplicate controls, why does this happen? 0 Answers