Help, cant get 2D sprite to animate correctly

I’m fairly new to unity and I have spent the last 2 hours searching for a solution, this seems to work in unity 4 but there must have been a change in unity 5. I have a idle animation and then a animation set to run when the speed is higher than 0.01. I don’t know what is going on, I get no errors and it simply doesn’t play the animation.

using UnityEngine;
using System.Collections;

[SerializeField]
public class PlayerController : MonoBehaviour {

public float maxSpeed = 10f;
bool facingRight = true;
public Rigidbody2D Rb;

public Animator anim;

void start ()
{

anim = GetComponent ();

}

void FixedUpdate ()
{
float move = Input.GetAxis (“Horizontal”);

anim.SetFloat(“Speed”, Mathf.Abs(move));

Rb.velocity = new Vector2 (move * maxSpeed, Rb.velocity.y);

if (move > 0 && !facingRight)
Flip ();
else if (move < 0 && facingRight)
Flip ();

}

void Flip()
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}

You can debug your statemachine with live link.
open up the animator windows and simply select your gameobject with your animator while in play mode.

You should see some live feedback and which state is currently playing. Also you can see live feedback on parameter so you can debug if your call to SetFloat(“Speed”) actually work.
If you still see your run state playing then my guess is that maybe apply root motion is disabled. We did change apply root motion behaviour between 4.x and 5.0


It simply loops the IdlePlayer :confused: the walking animation does nothing, the problem is that my code cant access the animator…

On this screen shot we cannot see your transition condition for IdlePlayer to Walking, could select this transition and take another screenshot?

Thanks but in another post on a different problem someone gave me the answer to solve this aswell without even meaning it…
I was trying to get the animator the old unity 4 way…

1 Like