Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 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
5
Question by ROM · Jun 18, 2010 at 04:14 PM · 3diphonetimerbasic

How to call a routine every 3 seconds?

Just wondering if there is an equivalent to Objective-C's "NSTimer" to allow you to call a routine every x amount of seconds? I've tried looking at WaitForSeconds but I'm not 100% sure what it's doing because it doesn't seem to work.

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

2 Replies

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

Answer by Mike 3 · Jun 18, 2010 at 04:20 PM

you can just use this:

InvokeRepeating("YourFunctionName", 3);

or (js):

function Start() { YourFunctionName(); }

function YourFunctionName() { while(true) { DoSomething(); yield WaitForSeconds(3); } }

or (c#):

using System.Collections;

public class YourClass {

 void Start()
 {
     StartCoroutine(YourFunctionName());
 }

 IEnumerator YourFunctionName()
 {
     while(true)
     {
         DoSomething();
         yield return new WaitForSeconds(3);
     }
 }

}

Comment
Add comment · Show 5 · 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 Cyclops · Jun 18, 2010 at 04:26 PM 0
Share

@$$anonymous$$ike, you could go ahead and put the Using statement into the code block, before Start - it doesn't have to be at top, just before any usage. (And Unity adds that line at top by default anyway, when you create a C# script).

avatar image Mike 3 · Jun 18, 2010 at 04:30 PM 0
Share

I did, it just went a bit wonky, I'll try edit it back in :P CommentEdit!: There, better :)

avatar image Cyclops · Jun 18, 2010 at 06:02 PM 0
Share

Yeah, sometimes the Code block flakes out on the first few lines, dunno why. Hope you don't $$anonymous$$d, I did go ahead and fix it so it wasn't a comment. :)

avatar image Mike 3 · Jun 18, 2010 at 06:08 PM 0
Share

no problem at all :D

avatar image BedrockLlama · Dec 19, 2015 at 11:46 AM 0
Share

Where do I put the code I want to repeat in (C#) and where do you declare DoSomething?

avatar image
0

Answer by synapsemassage · Nov 10, 2010 at 03:17 PM

correct Javascript syntax for InvokeRepeating would be: function InvokeRepeating (methodName : string, time : float, repeatRate : float) : void

example: InvokeRepeating("YourFunctionName", 0, 3);

"0" is the delaytime.

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

1 Person is following this question.

avatar image

Related Questions

Object generator? 1 Answer

Can I use unity 3d as a component of UI in ipad app? 0 Answers

Rotating doesn't work correctly? 2 Answers

Menu with 3D-objects - using swipe on iPhone 1 Answer

iPhone game with free 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