- Home /
How to make a "Run Stop" animation?
Hello there,
ive a basic 2D game where you control a character with idle,jump, run animations etc. They all work fine. Now i wanted to add a "Run Stop" animation like when the player is pressing left/right arrow key and then releasing it so the stop animation of the character starts.
But i dont know how to detect it. How can i say: "here you have to play the Run Stop Animation" ?.
Tryed several stuff non working. Thanks in advice
My code so far looks like this:
public float maxSpeed = 10.0F;
Animator anim;
void Start(){
anim = GetComponent();
}
void FixedUpdate(){
float move = Input.GetAxis("Horizontal");
//mathf abs because we do not want any negative values if we are moving 1 or -1 it just passes 1
anim.SetFloat("Speed",Mathf.Abs(move));
//just move left or right
//we do not need time.deltatime because we are in fixedupdate
rigidbody2D.velocity = new Vector2(move * maxSpeed, rigidbody2D.velocity.y);
}
Comment
Best Answer
Answer by clunk47 · Mar 12, 2014 at 03:57 PM
Look at the Unity Script Reference for GetComponent. You're not calling any type. The Script ref only shows an example in UnityScript, so I've provided a C# Example:
anim = GetComponent<Animator>();