How to add delay in update() function
Notes:
How to add delay to update() function in Unity:
- moving a cube up by 1 unit after every 3 seconds
- rotating a cube around y axis by 40 degrees after every 3 seconds
using UnityEngine;
public class CubeController : MonoBehaviour {
float time;
float timeDelay;
void Start () {
time = 0f;
timeDelay = 3f;
}
void Update () {
time = time + 1f * Time.deltaTime;
if (time >= timeDelay) {
time = 0f;
//this.transform.position = this.transform.position + new Vector3 (0f, 1f, 0f);
this.transform.eulerAngles = this.transform.eulerAngles + new Vector3(0f,40f,0f);
}
}
}