unity perform action every second code example
Example 1: unity call a function every x seconds
float x = seconds before the first invoke;
float y = seconds between every invoke;
InvokeRepeating("Function", x, y);
Example 2: 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
}
}