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

GameObject Search By Unity Tag

How to Install Unity UI Toolkit Package ?

Searching Multiple GameObjects By Unity Tag

What is Unity SiblingIndex ?

Unity Visual Studio Debug Problem