Hi.
I cannot seem to get my head around the implementation of WaitForSecondRealtime with CustomYieldInstructoin. Would really appreciate tips to the code. The Debug.Log(“after pause…”) never runs.
public class Test: MonoBehaviour {
void Update()
{
if(flag) {
StartCoroutine(Pause(5f));
SceneManager.LoadScene("NextScene");
}
}
IEnumerator Pause(float p)
{
Debug.Log("pause...");
yield return new WaitForSecondsRealtime(p);
Debug.Log("after pause..");
}
public class WaitForSecondsRealtime : CustomYieldInstruction
{
private float waitTime;
public override bool keepWaiting
{
get
{
return Time.realtimeSinceStartup < waitTime;
}
}
public WaitForSecondsRealtime(float time)
{
waitTime = Time.realtimeSinceStartup + time;
}
}
}