I just created the animation to run and jump with unity, but I have a problem when the player returns to IdlePlayer's initial state, when I stop running or jump it continues for another 1 second, I've already tried decrease the frames but nothing. Here is my code below and a print of the animation configuration:
public class Player : MonoBehaviour
{
public float velociadade;
public Transform player ;
public Transform Ground;
public Animator animator;
public bool isGround;
public float force = 200f;
public float jumpTime = 0.5f;
public float jumpDelay = 0.5f;
public bool jumped ;
void Start ()
{
animator = player.GetComponent<Animator> ();
}
void Update ()
{
Movimentar ();
}
void Movimentar ()
{
isGround = Physics2D.Linecast(this.transform.position,Ground.position,1<<LayerMask.NameToLayer("Plataforma"));
animator.SetFloat ("run", Mathf.Abs (Input.GetAxis ("Horizontal")));
if (Input.GetAxisRaw ("Horizontal") > 0) {
transform.Translate (Vector2.right * velociadade * Time.deltaTime);
transform.eulerAngles = new Vector2 (0, 0);
}
if (Input.GetAxisRaw ("Horizontal") < 0) {
transform.Translate (Vector2.right * velociadade * Time.deltaTime);
transform.eulerAngles = new Vector2 (0, 180);
}
bool up = Input.GetKeyUp(KeyCode.Space);
if (up && isGround && !jumped)
{
GetComponent<Rigidbody2D>().AddForce(transform.up * force);
jumpTime = jumpDelay;
animator.SetTrigger("jump");
jumped = true;
}
jumpTime -= Time.deltaTime;
if (jumpTime <= 0 && isGround && jumped) {
animator.SetTrigger("ground");
jumped = false;
}
}