이전에 Fade Out, Fade In을 만들었고
이를 활용해 화면을 클릭하면 씬을 전환하는 코드를 작성했다.
처음 작성할 때는 씬이 바로 전환되는 문제가 있어서
SceneLoad를 Fade Out이 진행되는 것을 기다리고 나서 실행시켰다.
# GameManager.cs
public void NextSceneString()
{
FadeInOut.StartFadeOut();
StartCoroutine(SceneLoad());
}
IEnumerator SceneLoad()
{
float waitTime = FadeInOut.GetFadeTime();
yield return new WaitForSeconds(waitTime);
SceneManager.LoadScene("MainScene");
FadeInOut.StartFadeIn();
}
waitTime
은 FadeInOut 클래스에서 시간을 가져왔고
그 시간만큼 Coroutine으로 기다린 뒤, MainScene을 로드했다.
# FadeInOut.cs
public void StartFadeIn()
{
StartCoroutine(Fade(1, 0));
}
public void StartFadeOut()
{
StartCoroutine(Fade(0, 1));
}
private IEnumerator Fade(float start, float end)
{
float currentTime = 0.0f;
float percent = 0.0f;
while (percent < 1)
{
currentTime += Time.deltaTime;
percent = currentTime / _fadeTime;
Color color = _image.color;
color.a = Mathf.Lerp(start, end, _fadeCurve.Evaluate(percent));
_image.color = color;
yield return null;
}
}
Fade InOut 함수는 위와 같다.
문제는 Fade역할을 해주는 UI Image가 시작 화면의 캔버스보다 위에 있어야 보이지만,
또 클릭은 되면 안되는 상황에서 좀 많이 해맸다.
해결 방법은 RayCast Taget을 풀어주는 것이었다.
이것 하나 때문에 많이 고생했는데... 너무 간단한 문제였다
생각이 계속 꼬여서 생각하지 못했던 것 같다.