- Home /
What do I type so that integers interact with the animator.
I've been attempting to make it so when my character (A yellow circle) goes one way an animation plays (ball rolls right when you go right) and when the character goes the other way the ball rolls likewise(ball rolls left when you go left). I have the animations linked in the Animator so that when I have the integer "A" equal to one or two, the two different are animations supposed to play depending on the value. I know that the animations work because when I make them the defaults the are fine, but I am unable to switch between left, right, and motionlessness.
Here is my code-
pragma strict
var moveright : KeyCode;
var moveleft : KeyCode;
var moveup : KeyCode;
var speed : float = 10;
var speedup : float = 10;
function Update () { if (Input.GetKey(moveleft))
{
{
rigidbody2D.velocity.x = speed *-1;
}
{
SetInteger("A", 2);
}
}
else if (Input.GetKey(moveright))
{
{
rigidbody2D.velocity.x = speed;
}
{
Animator.SetInteger("A", 1);
}
}
else if (Input.GetKey(moveup))
{
rigidbody2D.velocity.y = speedup;
}
else
{
rigidbody2D.velocity.x = 0;
}
}
I believe that Animator.SetInteger is the problem, but I don't know what to put in place of it. It also doesn't work If I use PlayerPrefs.SetInt.
Thanks!
You didn't cached the Animator so you should use:
gameObject.GetComponent(Animator).SetInteger("A", 2);
That was perfect, thanks! On a side note, do you have any ideas on how I could make it stop spinning? I need to make it so it becomes idle when you stop pressing the keys.
Thank you So much. Everything is working perfectly for me.
Your answer
Follow this Question
Related Questions
2d camera help! 0 Answers
random sprite javascript 0 Answers
How would I make a route that shows where player moves beforehand? 0 Answers
Integer in if statement, scripting help 1 Answer
Changing material orientation dependant on mouse location? 0 Answers