Advertisement
AnomalousUnderdog

Using coroutines

Jun 21st, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.63 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Example : MonoBehaviour
  5. {
  6.     // coroutines have to return IEnumerator
  7.     IEnumerator TestCoroutine()
  8.     {
  9.         Debug.Log("Test");
  10.         yield return new WaitForSeconds(5);
  11.         Debug.Log("Will display after 5 seconds");
  12.     }
  13.  
  14.     void Start()
  15.     {
  16.         // to make coroutines work, you have to call them
  17.         // using StartCoroutine
  18.         StartCoroutine(TestCoroutine());
  19.     }
  20.    
  21.    
  22.     void Update()
  23.     {
  24.         // invoke the coroutine whenever left mouse button is pressed
  25.         if (Input.GetMouseButtonDown(0))
  26.         {
  27.             // you can call coroutines from Update
  28.             StartCoroutine(TestCoroutine());
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement