Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Example : MonoBehaviour
- {
- // coroutines have to return IEnumerator
- IEnumerator TestCoroutine()
- {
- Debug.Log("Test");
- yield return new WaitForSeconds(5);
- Debug.Log("Will display after 5 seconds");
- }
- void Start()
- {
- // to make coroutines work, you have to call them
- // using StartCoroutine
- StartCoroutine(TestCoroutine());
- }
- void Update()
- {
- // invoke the coroutine whenever left mouse button is pressed
- if (Input.GetMouseButtonDown(0))
- {
- // you can call coroutines from Update
- StartCoroutine(TestCoroutine());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement