Use this to create a loop;
private IEnumerator LoopFunction(float waitTime)
{
while (true)
{
Debug.Log("print.");
yield return new WaitForSeconds(waitTime);
Debug.Log("print1.");
}
}
To call a function, do not use Update()or FixedUpdate(), use something like Start()so as not to create infinite loop instances;
void Start()
{
StartCoroutine(LoopFunction(1));
}
source
share