Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Aviratex · Sep 04, 2015 at 12:00 PM · c#scripting problemscripting beginnerdelayupdate function

HELP! How to make Update function start after delay? C#

Hey guys,

I'm new to unity and programming and I'm having some issues I hope you guys can help me with. I'm trying to create a delay before starting the Update function (is it even possible?). The script is for my character movement and I want there to be a slight delay before the user can start to move the character. This is what I have so far:

alt text

Sorry I had problems putting the Code in here so i took a picture.

So basically I want to make a short delay - maybe 2-3 seconds in which the player cant control the character. If there is any way I can accomplish this please help me out!

Thanks in advance!

capture.png (22.1 kB)
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

2 Replies

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

Answer by Positive7 · Sep 04, 2015 at 12:18 PM

 float time = 3.0f;
 
     void Update () {
 
         if(time >= 0){
             time -= Time.deltaTime;
             return;
         }else{
              //Do Something after clock hits 0
         }
        //Do Something else while clock counting down
 
 }
Comment
Add comment · Show 2 · 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 Aviratex · Sep 04, 2015 at 02:57 PM 0
Share

Thanks a lot! It worked but if you dont $$anonymous$$d could you explain why we write return; ?

avatar image Positive7 · Sep 04, 2015 at 03:31 PM 0
Share

Sorry you can delete return; I was going to do time -= Time.deltaTime; outside the if statement. Sent from mobile so I left it in by accident.

avatar image
0

Answer by Inok · Sep 29, 2015 at 11:41 PM

For delay in code execution better use coroutines Coroutines

Learn them and you will not want to back to primitive timers in update.

Comment
Add comment · Show 1 · 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 andzq · Apr 20, 2021 at 12:59 PM 0
Share

I just wanted to post an alternative to the already accepted answer that does not require a check within "Update".

     float delay = 1.0f;
     private void Awake()
     {
         Invoke(nameof(LateStart), delay);
     }
 
     void LateStart()
     {
         // your code
     }


// to lean in on the comment of "Inok" suggesting a coroutine, this is how that code could look like:

     float delay = 1.0f;
     private void Awake()
     {
         StartCoroutine(_LateStartRoutine(delay));
     }
 
     IEnumerator _LateStartRoutine(float delay)
     {
         yield return new WaitForSeconds(delay);
         // your late start code
     }

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

31 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Keeping Score out of Update Function 1 Answer

Rotate Player 90 degrees about its Y axis relative to the mouse being dragged between two angles 1 Answer

How to make a thrown object land on a certain point e.g a thrown spear landing on its tip 0 Answers

Having trouble deleting objects from a list after they reach a certain scale. 0 Answers

Problems with respawning using a very simple script 1 Answer


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