unity invokerepeating code example
Example 1: unity invoke
void Start()
{
Invoke("TurnLastPOff", 2);
}
public void StartWithDelay()
{
print("This should be printed after 2 seconds");
}
Example 2: unity interval timer
public Rigidbody projectile;
void Start(){
InvokeRepeating("LaunchProjectile", 2.0f, 0.3f);
}
void LaunchProjectile(){
Rigidbody instance = Instantiate(projectile);
instance.velocity = Random.insideUnitSphere * 5;
}
Example 3: unity invokerepeating
void Start()
{
InvokeRepeating("LaunchProjectile", 2.0f, 0.3f);
}
void LaunchProjectile()
{
Rigidbody instance = Instantiate(projectile);
}
Example 4: unity cancel invokerepeating
CancelInvoke();