Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

why "Example() " function does not excute?

Discussion in 'Scripting' started by guoliulong, Aug 16, 2012.

  1. guoliulong

    guoliulong

    Joined:
    Aug 16, 2012
    Posts:
    14
    using UnityEngine;
    using System.Collections;

    public class EnableScript : MonoBehaviour
    {
    private int ch = 100;
    // Use this for initialization
    void Start () {
    Example();
    }

    // Update is called once per frame
    void Update ()
    {
    Example();
    }

    void OnEnable()
    {
    GameObject gb = GameObject.Find("Main Camera");
    gb.GetComponent<Camera>().Render();
    }
    void OnDisable()
    {
    //print("Disable");
    }

    IEnumerator Example()
    {
    print("aa"+Time.time+1+ch);
    yield return new WaitForSeconds(5);
    print(Time.time+3);
    }

    }
     
  2. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,797
    You need to call it using StartCoroutine()

    so...

    Code (csharp):
    1. void Start () {
    2.    StartCoroutine("Example");
    3. }
     
  3. guoliulong

    guoliulong

    Joined:
    Aug 16, 2012
    Posts:
    14
    Thanks!