Coroutine은 yield구문을 만다면 곧바로 실행이 됩니다.
스크립트를 중지하거나 제거하면 yield이후의 구문은 실행되지 않습니다.
아래는 잘못된 코드입니다.
void Update()
{
if(health < 0)
{
StartCoroutine(Die());
Destroy(gameObject); //or enabled = false;
}
}
IEnumerator Die()
{
animation.Play("wobble");
yield return new WaitForSeconds(3);
//This will never be called
animation.Play("die");
}
아래와 같이 수정해야 정상동작을 수행합니다.
bool dying;
void Update()
{
if(dying) return;
if(health < 0)
{
StartCoroutine(Die());
}
}
IEnumerator Die()
{
dying = true;
animation.Play("wobble");
yield return new WaitForSeconds(3);
animation.Play("die");
yield return new WaitForSeconds(3);
Destroy(gameObject);
}
피드 구독하기:
댓글 (Atom)
-
mitmproxy( man in the middle proxy) 설치 메모 https://mitmproxy.org/ 에서 설치 방법 확인 brew를 사용해서 설치 진행 - $ brew install mitmproxy - 설치후...
-
컴파일 옵션을 -Wall하면 간혹 나타나는 오류임. 생성자의 초기화 순서는 헤더에서 선언된 순서와 일치하여야 한다는 의미임. 생성자에서 초기화 할때 상수가 아닌 변수로 초기화를 해버리면 그 순서때문에 초기값이 꼬일 수 있다는 거임.. stru...
-
CommandBuffer를 사용하여 Gray Post Effect 효과를 적용해보는 Simple code... 일단 보여지는 결과는... 실행전 실행후 CommmandBuffer를 이용한 C#예제 소스 using ...
댓글 없음:
댓글 쓰기