animation delay or wait

i am new to scripting so can anyone give me an example or any help of how i can delay an animation.

0
if you are using the more recent Animator you will have to combine 2 states to use the above.

Locate the animator window
you should see your animation there and be able to create a new empty State (right click on grid area and select “creat state” / “empty”), call in something like “waiting”. then right-Click it and select it has default state (becomes orange)
Then in your script:

 var startDelay : int;
 
 function Start()
 {
 var animator = GetComponent(Animator);
 yield WaitForSeconds(startDelay);
 animator.Play("animation_I_want_to_play");
 }

animation_I_want_play should match the name of your animation/state in the animator window.

old post but I stumbled over it recently so it hope this helps,

yield WaitForSeconds(4)

put this code before the animation and it should start after 4 seconds :) or you can make a simple script like so:

               function Start()
        {

        animation.Play("Put Your Animation name here ");

  }

Now the above script will trigger the animation as soon as you play the game. now if you want to delay the animation you do this:

    function Start()
   {

      yield WaitForSeconds(2);  
    animation.Play("Put Your Animation name here ");

   } 

now this will do the same as the code above but this time it will delay the animation for 2 seconds

hope this helps:)

Here’s a way that worked for me, in C#,

 public class StartAnimation : MonoBehaviour {
	
	Animator m_Animator;

	void Start()
	{
		m_Animator = gameObject.GetComponent<Animator>();
	}

	void Update()
	{		
		if (Time.timeSinceLevelLoad >= 10) {
			m_Animator.Play ("MyAnimation");
		} else {			
			m_Animator.Play ("Stop");  //Here another state
		}	
	}
}

Hi everyone. Does anyone have an update on how this currently works step by step? I have a cube called “cube”, an animation called “123” and an animation controller called “456”. The animation itself is the cube moving for a couple of meters. How do I go from here? Step by step. I’ve been trying every single code in the previous answers here for the last 4 hours but my cube just keeps ignoring my scripts and moves right after starting the game. The cube has an animation controller and the script is assigned to the cube too. Any help is really appreciated, thank you so much