Answers for "unity how to do something every x seconds"

C#
5

unity call a function every x seconds

float x = seconds before the first invoke;
float y = seconds between every invoke;

InvokeRepeating("Function", x, y);
Posted by: Guest on July-25-2020
1

Execute code every x seconds with Update()

private float nextActionTime = 0.0f;
 public float period = 0.1f;
 
 void Update () {
     if (Time.time > nextActionTime ) {
        nextActionTime += period;
         // execute block of code here
     }
 }
Posted by: Guest on June-25-2020
1

unity how to do something every x seconds

private float nextActionTime = 0.0f;
// every 1f = 1 second
public float period = 1f;

void Update() 
{
	if (Time.time > nextActionTime)
	{
		nextActionTime = Time.time + period;
  		/*
        * code here
        */
	} 
}
Posted by: Guest on August-22-2021
-1

Unity Timer every x seconds

private float nextActionTime = 0.0f; 
 public float period = 0.1f;  
 void Update () {     
 if (Time.time > nextActionTime ) {
 nextActionTime += period;
 // execute block of code here
 	}
 }
Posted by: Guest on August-04-2021

Code answers related to "unity how to do something every x seconds"

C# Answers by Framework

Browse Popular Code Answers by Language