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 /
avatar image
0
Question by oliver344 · Jul 12, 2011 at 11:46 AM · yielddynamicinvokeraterepeating

Invoke Repeating Rate

Hi,

i have this code:

InvokeRepeating("SetTime", 0, timeSpawn);

and i have the timeSpawn variable changing, so i need this to be dynamic. What i find out is that i cant directly change rate of invoke like this as it is called only once.

Is there some way around it ? I read here about using yielding for this. But i kind of struggle with it. Is there any solution to have dynamic invoke repeating ?

thanks

Luke

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
5
Best Answer

Answer by Waz · Jul 12, 2011 at 12:12 PM

Just write the code manually as a co-routine:

 function SpawnStuff()
 {
     while (true) {
         SetTime();
         yield WaitForSeconds(timeSpawn);
     }
 }

Then just call that function to start it invoking, just as you currently do with InvokeRepeating.

No need to fear coroutines.

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 RandomCharacters · Sep 03, 2013 at 05:17 AM 0
Share

This answer is overly vague (as is most of the answers here). So SetTime(); is not a function monodevelop found. What is this? timespawn is a float number variable, I get that. Anyone?

Also, the (true), I am assu$$anonymous$$g that while this is true, this keeps repeating. How do you set it to false? I'm a newbee, sorry.

avatar image CipherZero · Jan 10, 2014 at 02:51 AM 1
Share

SetTime() is a function oliver344 using in his/her own program, it has nothing to do with $$anonymous$$onoDevelop. Using "while(true)" means it will stays true til the end of the time. Of course you can change "true" to anything else you need. It really depends on what you're trying to achieve.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Why does this not work? 1 Answer

Invoke.Repeating doesn't really "care" about repeat time? 1 Answer

Invoke/yield in non MonoBehaviour classes 1 Answer

InvokeRepeating affecting parts of script 1 Answer

How to Invoke() .. one frame 2 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