블로그 이미지
Every unexpected event is a path to learning for you.

카테고리

분류 전체보기 (2737)
Unity3D (817)
Programming (474)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (228)
협업 (58)
3DS Max (3)
Game (12)
Utility (136)
Etc (96)
Link (32)
Portfolio (19)
Subject (90)
iOS,OSX (53)
Android (14)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (3)
Memories (20)
Interest (38)
Thinking (38)
한글 (30)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (18)
Exercise (3)
나만의 맛집 (3)
냥이 (10)
육아 (16)
Total
Today
Yesterday
04-20 00:00

참조 : http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.StopCoroutine.html


void StopCoroutine(string methodName);


StopCoroutine은 위와같은 형태이다. Stop시킬 Method를 string 형태로 해야한다.


생각없이 쓰려다가 안돼서 레퍼런스를 다시 보니 이전에도 봤던기억이 있는 아래와 같은 문장이..;;

(역시 사람은 망각의 동물..)


Please note that only StartCoroutine using a string method name can be stopped using StopCoroutine.


StopCoroutine을 쓰려면 StartCoroutine도 string형태의 method name으로 실행해야 한다.


또 까먹을까봐 정리해놓음.



[추가 Tip]

StartCoroutine으로 같은 이름의 함수를 여러번 실행해도, StopCoroutine을 해당 함수명으로 한 번만 실행하면 같은 함수명을 가진 Coroutine이 모두 중지된다.


ex)

using UnityEngine;
using System.Collections;

public class Example : MonoBehaviour
{
    IEnumerator Start()
    {
        StartCoroutine("DoSomething", 2.0F);
        StartCoroutine("DoSomething", 4.0F);
        yield return new WaitForSeconds(1f);
        StopCoroutine("DoSomething"); // 한 번만 실행해도 위에서 실행된 DoSomething Coroutine 2개가 모두 취소된다.
    }
    IEnumerator DoSomething(float someParameter)
    {
        while (true)
        {
            print("DoSomething Loop" + someParameter);
            yield return null;
        }
    }
}
반응형
Posted by blueasa
, |