Answers for "how to wait for seconds in unity ienumerator"

C#
1

unity ienumerator wait for seconds

using UnityEngine;
using System.Collections;public class WaitForSecondsExample : MonoBehaviour
{
    void Start()
    {
        //Start the coroutine we define below named ExampleCoroutine.
        StartCoroutine(ExampleCoroutine());
    }    IEnumerator ExampleCoroutine()
    {
        //Print the time of when the function is first called.
        Debug.Log("Started Coroutine at timestamp : " + Time.time);        //yield on a new YieldInstruction that waits for 5 seconds.
        yield return new WaitForSeconds(5);        //After we have waited 5 seconds print the time again.
        Debug.Log("Finished Coroutine at timestamp : " + Time.time);
    }
}
Posted by: Guest on October-10-2021
5

unity wait for seconds

void start() => StartCoroutine(MyIEnumerator());

IEnumerator MyIEnumerator()
{
	Debug.Log("Hello world!");
    yield return new WaitForSeconds(3);
    Debug.Log("Goodbye world!");
}
Posted by: Guest on February-03-2021

C# Answers by Framework

Browse Popular Code Answers by Language