ÄÚ·çƾ

¸ð¹ÙÀÏ ±â±â¿Í OS¿¡ µû¶ó ÇØ»óµµ ¼³Á¤ ¹æ¹ýÀÌ ´Ù¸£´Ù.

ÄÚ·çƾÀº ¾²·¹µå¿Í ºñ½ÁÇØ º¸ÀÌÁö¸¸ ¾²·¹µå¿Í´Â ´Ù¸¥´Ù.
¾²·¹µå´Â º´·Ä·Î µ¿ÀÛÇÏÁö¸¸, ÄÚ·çƾÀº ¸ÞÀξ²·¹µå¿¡¼­ Á÷·Ä·Î ½ÇÇàµÈ´Ù.

¿¹Á¦1) ±âº» ¿¹Á¦

public class MainScript : MonoBehaviour

{

    void Start ()

    {

        StartCoroutine ("Other");

    }

 

    IEnumerator Other ()

    {

        print ("Other() Method");

        return null;

    }

}

Start( )¿Í Other( )´Â °°Àº ¾²·¹µå·Î Other( ) ÇÔ¼ö°¡ Çѹø ¾ÁÇàµÈ´Ù.

 

¿¹Á¦2) 2Ãʸ¶´Ù Çѹø¾¿ ½ÇÇàµÇ´Â ¸í·É¾î

public class MainScript : MonoBehaviour

{

    void Start ()

    {

        StartCoroutine ("Other");

        print ("Run Start");

    }

 

    IEnumerator Other ()

    {

        print ("Other() Method");

        yield return new WaitForSeconds (2);

        print ("After WaitForSeconds() Method");

        StartCoroutine ("Other");

    }

}

½ÇÇà °á°ú)

Other() Method
Run Start
After WaitForSeconds()
Other( ) Method
After WaitForSeconds()

Other( ) Method

...... ¹Ýº¹


¿¹Á¦3) ¼øÂ÷ÀûÀ¸·Î ½ÇÇà µÇ´Â ¸í·É¾î

public class CoRoutineTest : MonoBehaviour

{

    IEnumerator Start ()

    {

        Debug.Log ("Action Start");

        yield return new WaitForSeconds(1.0f);

        Debug.Log ("Action1 End");

        yield return new WaitForSeconds(2.0f);

        Debug.Log ("Action2 End");

    }   

}

½ÇÇà °á°ú

½Ã°£ÈÄ¿¡ Â÷·Ê´ë·Î ½ÇÇàµÈ´Ù.
Start( ) ÇÔ¼ö¸¦ IEnumerator·Î ¼±¾ðÇϸé ÀÚµ¿À¸·Î ÄÚ·çƾÀ¸·Î ½ÇÇàµÈ´Ù.

Action Start

Action1 End

Action2 End

 

¿¹Á¦ 4) À¥À¸·Î ´Ù¿î·Îµå ¹ÞÀ¸¸é 0.5Ãʸ¶´Ù UI Ç¥½Ã
0.5Ãʸ¶´Ù ÁøÇà»óÅ ±×¸®±â.

public class CoRoutineTest : MonoBehaviour

{

    WWW www;

 

    IEnumerator Start ()

    {

        www = new WWW("www.daum.net");

        StartCoroutine("CheckProgress");

        yield return www;

        Debug.Log ("Download Completed!");

    }

 

    IEnumerator CheckProgress()

    {

        Debug.Log (www.progress);

        while(!www.isDone)

        {

            yield return new WaitForSeconds(0.5f);

            Debug.Log (www.progress);

        }

    }

}

 

¿¹Á¦ 5)ÄÚ ·çƾÀ¸·Î FadeIn È¿°ú

¿ÀºêÁ§Æ®ÀÇ ¸ÞÆ®¸®¾ó ½¦ÀÌ´õ°¡ Transparent ¼Ó¼ºÀ¸·Î µÇ¾î ÀÖ¾î¾ß ÇÑ´Ù.

public class CsFadeIn : MonoBehaviour

{

    void Start () {

        StartCoroutine("FadeIn");

    }

 

    IEnumerator FadeIn()

    {

        for(float i = 1f; i >= 0; i -= 0.1f)

        {

            Color color = new Vector4(1,1,1, i);

            transform.renderer.material.color = color;

            yield return 0;  //´ÙÀ½ ÇÁ·¹ÀÓ±îÁö ´ë±â

        }

     }

}

 

¿¹Á¦ 6) ÀÏÁ¤ ½Ã°£µ¿¾È ¿ÀºêÁ§Æ® »ý¼ºÀ» ÇÏÁö ¸øÇϵµ·Ï ÇÒ¶§

public class CsMoveExample : MonoBehaviour {

    public Transform missile;

    bool canFire;

    // Use this for initialization

    void Start () {

    }

 

    // Update is called once per frame

    void Update () {

        ShootMissile();

    }

    void ShootMissile()

    {

        //canFire °ª trueÀ϶§¸¸ ½ÇÇà

        if(Input.GetButton("Fire1") && canFire)

        {

            MonoBehaviour.StartCoroutine("MakeMissile");

        }

    }

    IEnumerator MakeMissile()

    {

        canFire = false;

        //¹Ì»çÀÏ»ý¼º

        Instantiate(missile, transform.position, Quaternion.identity);

        yield return new WaitForSeconds(0.2f); //0.2ÃÊ°£ ½ÇÇàÀ» º¸·ùÇÑ´Ù.

        canFire = true; //canFire°ª true·Î º¯°æ

    }

}

 

ÂüÁ¶)
http://www.unitystudy.net/bbs/board.php?bo_table=writings&wr_id=43

http://hyunity3d.tistory.com/383