using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CilckMoveFade : MonoBehaviour
{
public float animTime = 0.5f; // Fade 애니메이션 재생 시간 (단위:초).
public Image fadeImage; // UGUI의 Image컴포넌트 참조 변수.
void Awake()
{
// Image 컴포넌트를 검색해서 참조 변수 값 설정.
}
public void FadeIn(float fadeOutTime, System.Action nextEvent = null)
{
StartCoroutine(CoFadeIn(fadeOutTime, nextEvent));
}
public void FadeOut(System.Action nextEvent = null)
{
StartCoroutine(CoFadeOut(animTime, nextEvent));
}
// 투명 -> 불투명
IEnumerator CoFadeIn(float fadeOutTime, System.Action nextEvent = null)
{
Color tempColor = fadeImage.color;
while (tempColor.a < 1f)
{
tempColor.a += Time.deltaTime / fadeOutTime;
fadeImage.color = tempColor;
if (tempColor.a >= 1f) tempColor.a = 1f;
yield return null;
}
fadeImage.color = tempColor;
if (nextEvent != null) nextEvent();
}
// 불투명 -> 투명
IEnumerator CoFadeOut(float fadeOutTime, System.Action nextEvent = null)
{
Color tempColor = fadeImage.color;
tempColor.a = 1;///불투명으로 설정
while (tempColor.a > 0f)
{
tempColor.a -= Time.deltaTime / fadeOutTime;
fadeImage.color = tempColor;
if (tempColor.a <= 0f) tempColor.a = 0f;
yield return null;
}
fadeImage.color = tempColor;
if (nextEvent != null) nextEvent();
}
}
댓글 없음:
댓글 쓰기