-2

I am new to programming in C# and i don t know make a delay.

My goal is to invert the gravity for 3 seconds and then change it back after 1 second. I want to do this in the update

1 Answers1

0

You can use Coroutine (documentation here: https://docs.unity3d.com/Manual/Coroutines.html) and a simple bool.

Example:

private bool isCoroutineExecuting = false;
 
 IEnumerator ExecuteAfterTime(float waittime)
 {
     if (isCoroutineExecuting)
         yield break;
 
     isCoroutineExecuting = true;

     // Code to execute before the delay
 
     yield return new WaitForSeconds(waittime);
  
     // Code to execute after the delay
 
     isCoroutineExecuting = false;
 }

A call it with StartCoroutine(ExecuteAfterTime(waittime));

danlvr
  • 1
  • 2