2017-04-24 4 views
0

저는 하나의 프로젝트에서 작업하고 있습니다. 페이드 인 (fade in)과 페이드 아웃 (fade out) 애니메이션으로 장면을 전환하고 싶습니다. 애니메이션이 끝났고 액세스 할 수 있지만 자습서에서 yield 및 Ienumerator 함수로 작업하고 있지만 제대로 작동하지 않습니다.애니메이션이 완성 될 때까지 기다릴 수있는 방법은 무엇입니까?

//from my animation script 
public IEnumerator fadeIn() 
{ 
    isFading = true; 
    animator.SetTrigger("FadeIn"); 
    while (isFading) 
    { 
     yield return new WaitForSeconds(3f); 
    } 
} 

// from my main menu script. 
public void btnPlay() 
{ 
    StartCoroutine(fadeIn()); 
    Debug.Log("AfterIn"); 
    SceneManager.LoadScene("playOptions"); 
    StartCoroutine(fadeOut()); 
    Debug.Log("AfterOut"); 
} 

IEnumerator fadeIn() 
{ 
    yield return StartCoroutine(animatorscript.fadeIn()); 
} 
IEnumerator fadeOut() 
{ 
    yield return StartCoroutine(animatorscript.fadeOut()); 
} 

질문이 업데이트되었습니다. 그러나 내가 그것을 실행할 때 나는 애니메이션을 본다. 그것은 다음 장면으로 직접 이동하고 디버그 메시지는 서로에게 직접 전달됩니다.

+0

제목이 사용자의 질문과 일치하지 않습니다. Unity가 무엇을 기다리고 싶습니까? 페이드 아웃 애니메이션? –

답변

1

Coroutine을 시작하려면 과 같은 방식으로 StartCoroutine(fadeIn)과 같이 호출해야합니다.

그래서 당신은 StartCoroutine

UPDATE에

public void btnPlay() 
{ 
    StartCoroutine(fadeIn); 
    SceneManager.LoadScene("playOptions"); 
    StartCoroutine(fadeOut); 
} 

자세한 내용은 here를 참조 추가해야 업데이트 된 질문에 관해서는, 나는 당신이 fadein 장면을로드가 완료 될 때까지 기다려야 할 가정 .

다음과 같은 것이 트릭입니다.

public void btnPlay() 
{ 
    StartCoroutine(SceneFadeAndLoad); 
} 

IEnumerator SceneFadeAndLoad() 
{ 
    yield return StartCoroutine(fadeIn); 
    SceneManager.LoadScene("playOptions"); 
    yield return StartCoroutine(fadeOut); 
} 
+0

코 루틴을 사용할 때'using System.Collections; '문을 잊지 마세요. –

+0

여전히 작동하지 않습니다. –

+0

질문이 업데이트되었습니다. –

관련 문제