What is Unity StartCoroutine ?

If you want to give a time interval before an action is performed in Unity, the "StartCoroutine" method is used.

Let's examine the example below..

public void GoToExit() { StartCoroutine("ExitBegin"); } IEnumerator ExitBegin() { yield return new WaitForSeconds(1f); SceneManager.LoadScene("MainMenu"); }

In our example, when our "GoToExit()" method was called, StartCoroutine directed us to our "ExitBegin" method, which returns the "IEnumerator" interface.

Here too it suspends execution at the specified time (1f - 1 second), using the "WaitForSeconds" class. Afterwards, it directed us to the "MainMenu" screen.



You May Interest

Checking If Unity GameObject Has Child Object

What is Unity Header and Space Feature?

What is Unity NPC?

How to Install Unity UI Toolkit Package ?

Unity Exit Example