구현 방법
1. Panel 생성
Panel을 생성해서 color.a 값을 중간 정도로 설정한 뒤, 칼라를 설정한다.
2. 스크립트 작성
FadeInOut
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class FadeInOut : MonoBehaviour
{
[SerializeField] private float _fadeTime; // 페이드 되는 시간
private void Start()
{
// Fade In <-> Fade Out 무한 반복
StartCoroutine(COFadeInOut());
}
private IEnumerator COFadeInOut()
{
while (true)
{
// 알파 값이 0.5에서 0으로
yield return StartCoroutine(Fade(0.5f, 0));
// 알파 값이 0에서 0.5로
yield return StartCoroutine(Fade(0, 0.5f));
}
}
private IEnumerator Fade(float start, float end)
{
float current = 0;
float percent = 0;
while (percent < 1)
{
current += Time.deltaTime;
percent = current / _fadeTime;
Color color = transform.GetComponent<Image>().color;
color.a = Mathf.Lerp(start, end, percent);
transform.GetComponent<Image>().color = color;
yield return null;
}
}
}
'유니티' 카테고리의 다른 글
앱 이름 한글 설정 (0) | 2024.04.19 |
---|---|
Json 데이터 저장 (0) | 2024.04.03 |
2D 화살 구현 (포물선 운동) (0) | 2024.03.25 |
SpawnSystem 구현 (1) | 2024.03.21 |
충돌 무시 (LayerCollisionMatrix) (0) | 2024.03.21 |