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
2
Question by Matt 15 · Jan 03, 2011 at 04:02 AM · waitforsecondsflow

interrupt WaitForSeconds() ?

Hey Unity Answers! Is there a way to interrupt a function that is currently waiting at the "WaitForSeconds()" step?

My situations is as follows: I have boxes that move every 5 seconds, so, I have a WaitForSeconds(5) in this function that I'm using, and it works great. However, when the next level starts, I need to destroy these boxes, load the next level and new boxes, and start moving them around every 5 seconds again.

When this happens, I get strange results in the timing that the boxes move. Sorta like, 5 seconds, move, 2 seconds move... My current thoughts are that since the player can go to the next level at any time, even if my function is in the waiting period, the timing in my game is getting shifted. Because, when I load the next level, the timing is all messed up, and it changes every 5 seconds, AND every 5 seconds from when the next level started.

So, what I'm hoping to do is, have some sort of exit from the WaitForSeconds, that if a bool is set to true, that it jumps out of the function. Is there something out there that I am just totally overlooking?

Thanks in advance!

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

1 Reply

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

Answer by Eric5h5 · Jan 03, 2011 at 04:12 AM

Make your own WaitForSeconds routine that is interruptible:

private var cancelWait = false;

function Wait (waitTime : float) { var t = 0.0; while (t <= waitTime && !cancelWait) { t += Time.deltaTime; yield; } }

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 jjmontes · Apr 09, 2020 at 11:54 PM 0
Share

$$anonymous$$y compiler requires yield return null; ins$$anonymous$$d of yield;.

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

1 Person is following this question.

avatar image

Related Questions

Csharp: how to make script wait for x seconds 3 Answers

About WaitForSeconds 1 Answer

Trying to make WaitForSeconds work 3 Answers

Sensitivity sliders not working 1 Answer

Can someone please tell me whats wrong with my code - the error syas it expects to see ')' instead it saw 'hit' (the one after 'out') 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