unity only do something every 2 seconds code example
Example 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
}
}
Example 2: unity do task 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
}
}