Engine/UnityNote
[Unity] 오브젝트 비활성화 시 코루틴
11월1일
2019. 10. 10. 22:49
코루틴은 해당 코루틴을 동작시키는 스크립트가 달린 오브젝트가 비활성화 됐을 때 동작하지 않는다.
public class ForCoroutineTest : MonoBehaviour
{
// Use this for initialization
void Start()
{
StartCoroutine(TestCoroutine()); // 코루틴 활성화
Invoke("ActiveFalse", 3.0f); // 3초후 비활성화
}
IEnumerator TestCoroutine()
{
while (true)
{
yield return null;
Debug.Log("활성화");
}
}
void ActiveFalse()
{
this.gameObject.SetActive(false);
}
}