system
1
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!
Mike_3
2
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);
}
}
}
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.