Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Sep 15, 2014 at 01:43 PM by galaboy for the following reason:

The question is answered, right answer was accepted

avatar image
3
Question by galaboy · Feb 25, 2014 at 11:00 AM · scriptingbasicsinvokerepeating

how does invokerepeating work

can anyone help me, by explaining how invokeRepearting works. i couldn't able to understand the last variable repeatRate. need help.

Comment
Add comment · Show 2
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 fafase · Feb 25, 2014 at 11:16 AM 0
Share

http://unitygems.com/mistakes1/ look at the $$anonymous$$ake Somethin Happen in the Future section.

avatar image Olakehs · Dec 11, 2019 at 12:02 AM 0
Share

Why use this ins$$anonymous$$d of just putting what you need in Update()?

2 Replies

  • Sort: 
avatar image
6
Best Answer

Answer by AlkisFortuneFish · Feb 25, 2014 at 11:12 AM

Read the documentation.

"After the first invocation repeats calling that function every repeatRate seconds."

So, if you do InvokeRepeating("Function", 1.0f, 1.0f), it will call Function one second after the InvokeRepeating call and then every one second thereafter.

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 AndrAla · Mar 10, 2017 at 09:02 PM 0
Share

I just watched an online Unity lesson, where they showed something like: float delayTime = 1f; InvokeRepeating("Foo", delayTime, delayTime);

void Foo(){ delayTime += 1f; // other stuff }

From my not-so-vast program$$anonymous$$g knowledge - this shouldn't work in the way they intended, and the function will keep repeating itself every 1 sec, and the delay shouldn't be increasing every time it's called. However, I may be wrong, since the ones that did this are more experienced. So.. would this function be called on the 1-st, 3-rd, 6-th, 10-th... second, or will it be called every second?

avatar image
1

Answer by Ertai7 · Feb 25, 2014 at 11:18 AM

The difference to the regular Invoke is that InvokeRepeating repeats itself. The first argument is the initial delay, the second the time that will pass until the Invoke is called again.

For instance, to implment a countdown timer you could use:

 public int timerSeconds = 60;
 
 InvokeRepeating ("Countdown", 1, 1);
 
 void CountDown()
 
 {
 
   timerSeconds--;
 
   if(timerSeconds < 1)
 
   {
 
     print ("Count down finished");
 
     CancelInvoke("CountDown");
 
   }
 
 }
Comment
Add comment · Show 3 · 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 fafase · Feb 25, 2014 at 11:21 AM 0
Share

If you want to give an example, give a proper one well indented. The Invoke method cannot just be there on its own.

avatar image galaboy · Feb 25, 2014 at 12:22 PM 0
Share

thanks for the explanations, so

1st variable is $$anonymous$$ethod Name. 2nd variable is timedelay. 3rd variable is then how many seconds after the call has to be made.

avatar image fafase · Feb 25, 2014 at 12:25 PM 1
Share

First is the method as string, second is the delay before first call and giving a value of 0 has been buggy (dunno if they fixed it) so if you need to start right on use a tiny value like 0.001. Last parameter is frequency of call after the first.

 InvokeRepeating ("Countdown", 10f, 5f);

First call after 10s, all other calls after will come every 5s.

Follow this Question

Answers Answers and Comments

24 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

Related Questions

invoke repeating not working 1 Answer

No OverLoad method for button takes 4 argumets? 1 Answer

I want my score to reset back to 0 but keep my highscore saved 3 Answers

Accessing components via script and assigning randomized values to their parameters? 1 Answer

Use vim with unity? 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