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

Using Unity Editor Black Theme

Checking If Unity GameObject Has Child Object

Searching Multiple GameObjects By Unity Tag

Unity Exit Example

What is Unity MonoDevelop ?