Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

unity coroutine

void Start() {
  StartCoroutine("func"); // Start coroutine named "func"
}

IEnumerator func() {
  Debug.Log("Hello");
  yield return new WaitForSecondsRealtime(1); //Wait 1 second
  Debug.Log("World");
}
Comment

how to write coroutine in unity

using UnityEngine;
using System.Collections;// In this example we show how to invoke a coroutine and execute
// the function in parallel.  Start does not need IEnumerator.public class ExampleClass : MonoBehaviour
{
    private IEnumerator coroutine;    void Start()
    {
        // - After 0 seconds, prints "Starting 0.0 seconds"
        // - After 0 seconds, prints "Coroutine started"
        // - After 2 seconds, prints "Coroutine ended: 2.0 seconds"
        print("Starting " + Time.time + " seconds");        // Start function WaitAndPrint as a coroutine.        coroutine = WaitAndPrint(2.0f);
        StartCoroutine(coroutine);        print("Coroutine started");
    }    private IEnumerator WaitAndPrint(float waitTime)
    {
        yield return new WaitForSeconds(waitTime);
        print("Coroutine ended: " + Time.time + " seconds");
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: Type is not marked as serializable. 
Csharp :: Change fog setting Unity 
Csharp :: for loop unity 
Csharp :: asp.net data annotations Datetime 
Csharp :: unity editor select object in script 
Csharp :: unity find gameobject by name 
Csharp :: loop through enum c# 
Csharp :: randomize through array in C# 
Csharp :: c# append to file 
Csharp :: how to flip character in unity 2d 
Csharp :: read file c# 
Csharp :: c# output double with precision 
Csharp :: csharp string to double 
Csharp :: bold caption latex 
Csharp :: c# loop through array 
Csharp :: c# log to console 
Csharp :: c# insert into database 
Csharp :: get random number c# 
Csharp :: load scene unity 
Csharp :: unity know when gameobject presed 
Csharp :: unity scenenmananger 
Csharp :: wpf label text color rgb string 
Csharp :: c# int to byte array 
Csharp :: unity list of gameobjects 
Csharp :: addding two numebrs with c# 
Csharp :: unity system time 
Csharp :: how to be like bill gates 
Csharp :: how to draw over label C# 
Csharp :: Codewars Multiply 
Csharp :: if string contains number c# 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =