using System.Collections;
using UnityEngine;
using UnityEngine.UI;
public class CutSceneManager : MonoBehaviour
{
public Image[] images;
public Text[] texts;
[SerializeField]
private float fadeDuration;
float cutTime = 0;
private void Start()
{
foreach (Image image in images)
{
Color imageColor = image.color;
imageColor.a = 0f;
image.color = imageColor;
}
foreach (Text text in texts)
{
Color textColor = text.color;
textColor.a = 0f;
text.color = textColor;
}
StartCoroutine(FadeCut());
}
IEnumerator FadeCut()
{
for (int i = 0; i < images.Length; i++)
{
StartCoroutine(FadeIn(images[i], texts[i]));
yield return new WaitForSeconds(fadeDuration + 4);
StartCoroutine(FadeOut(images[i], texts[i]));
yield return new WaitForSeconds(fadeDuration);
}
}
IEnumerator FadeIn(Image image, Text text)
{
Color imageColor = image.color;
Color textColor = text.color;
while (cutTime <= fadeDuration)
{
cutTime += Time.deltaTime;
imageColor.a = cutTime / fadeDuration;
image.color = imageColor;
textColor.a = cutTime / fadeDuration;
text.color = textColor;
yield return null;
}
cutTime = 0f;
}
IEnumerator FadeOut(Image image, Text text)
{
Color imageColor = image.color;
Color textColor = text.color;
while (cutTime <= fadeDuration)
{
cutTime += Time.deltaTime;
imageColor.a = 1 - cutTime / fadeDuration;
image.color = imageColor;
textColor.a = 1 - cutTime / fadeDuration;
text.color = textColor;
yield return null;
}
cutTime = 0f;
}
}
스토리 컷 편집을 유니티에서 보여줄 때,
일반적으로 사용하는 방법은 스타트 코루틴과 이넘레이터를 사용해서 구현한다.
'유니티' 카테고리의 다른 글
[유니티] Coroutine 작동 방식 및 yield의 역할 (0) | 2025.03.05 |
---|---|
[유니티] SkyBox 개념과 적용 방법 (0) | 2025.03.04 |
[유니티] Canvas에 캐릭터 걷는 애니메이션 넣기 (0) | 2025.02.25 |
[유니티] 스크립트 만들 때, Camera 라는 이름으로 만들지 말기 (0) | 2025.02.24 |
[유니티] Lerp 함수에 대한 이해와 사용 (0) | 2025.02.21 |