Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

How to make it each time when I switch between animations start from Idle state?

Discussion in 'Animation' started by megahappydead, Dec 15, 2019.

  1. megahappydead

    megahappydead

    Joined:
    Jan 16, 2019
    Posts:
    2
    I have a dance game and I want to smooth transitions.... I want somehow to make each time I click button start it from Idle state


    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class Robber : MonoBehaviour {
    public Animator anim;

    // Start is called before the first frame update
    void Start()
    {
    anim = GetComponent<Animator> ();
    }

    // Update is called once per frame
    void Update()
    {
    if (Input.GetKeyDown ("0"))
    {
    print ("Idle");
    anim.Play ("Idle", -1, 0f);
    }


    if (Input.GetKeyDown ("1"))
    {
    print ("Slowdance");
    anim.Play ("slow_dance", -1, 0f);
    }


    if (Input.GetKeyDown ("2"))
    {
    print ("Middance");
    anim.Play ("Mid_dance", -1, 0f);
    }

    if (Input.GetKeyDown ("3"))
    {
    print ("Fast_dance");
    anim.Play ("Fast_dance", -1, 0f);
    }
    }
    }
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,491
    Use CrossFade or CrossFadeInFixedTime instead of Play to get smooth transitions.
     
    megahappydead likes this.
  3. megahappydead

    megahappydead

    Joined:
    Jan 16, 2019
    Posts:
    2
    thank u : )


    video if someone have the same problem