Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
6
Question by zeuo · Nov 29, 2010 at 04:02 AM · animationdelaywait

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by MC HALO · Nov 29, 2010 at 04:10 AM

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:)

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image zeuo · Nov 29, 2010 at 11:05 PM 0
Share

i see i get it but the function why did u put start, isnt it function update

avatar image MC HALO · Nov 30, 2010 at 03:32 AM 0
Share

Yea you can use it in update as well i just did this because it is like an example. to help you :)

avatar image slugKid68 · Feb 09, 2017 at 07:01 PM 0
Share

Is there any way that I could get an example in C#? Im trying to do this exact thing and my poor attempt at converting javascript to C# doesn't work.

avatar image Happy-Zomby slugKid68 · Feb 10, 2017 at 08:23 AM 0
Share

Hi, i believe the above method is obsolete and you should use the one I mentioned in the post below - including the set-up in animator. I posted the c++ code for that. If you want to try the above regardless you should be able to get the c++ needed items from my code below: mainly StartCoroutine(DelayedAnimation()); //and IEnumerator DelayedAnimation () { yield return new WaitForSeconds(startDelay);

hope that helps

avatar image
7

Answer by Happy-Zomby · Nov 20, 2014 at 09:26 AM

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,

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Happy-Zomby · Feb 10, 2017 at 08:19 AM 1
Share

Same code as above but in C++,

     public int startDelay;
     Animator animator;
 
     // Use this for initialization
     void Start ()
     {
         animator = GetComponent<Animator>();
         StartCoroutine(DelayedAnimation());
     }
     
     // The delay coroutine
     IEnumerator DelayedAnimation ()
     {
         yield return new WaitForSeconds(startDelay);
         animator.Play("animation_I_want_to_play");
     }
avatar image slugKid68 Happy-Zomby · Feb 14, 2017 at 03:44 PM 0
Share

Thanks!

with the animator.Play("animation_I_want_to_play") am I targeting the animation controller attached to the object? I can stop the animation but it wont play.

avatar image Happy-Zomby slugKid68 · Feb 14, 2017 at 06:16 PM 0
Share

i can't recall the exact details of how I tested this at the time but yes I believe you should have the animator component on the object itself. If on a child you can use getcomponentinchildren (or something like that). When testing you need to look at the animator window - (Window - animator) and you should see if your "states" changes to orange and indicates a playing bar.

Show more comments
avatar image
0

Answer by rrivas2009 · Jun 05, 2020 at 07:35 AM

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
         }    
     }
 }
 
 

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by wohoyefe · Jul 17, 2021 at 06:01 AM

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Animation delay until certain distance 3 Answers

Slowing down the speed of my bullets whilst holding in the key. 1 Answer

How do I put a delay in this? 2 Answers

Idle animation plays while running (2D) 1 Answer

How to WaitforSeconds a GuiButton ? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges