using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Blink : MonoBehaviour
{
Image img;
Color color;
private void Awake()
{
img = GetComponent<Image>();
}
// Start is called before the first frame update
void Start()
{
StartCoroutine(FadeImage(true));
Color color = img.color;
color.a = 0f;
img.color = color;
}
// Update is called once per frame
void Update()
{
}
IEnumerator FadeImage(bool fadeAway)
{
// fade from opaque to transparent
if (fadeAway)
{
// loop over 1 second backwards
for (float i = 1; i >= 0; i -= Time.deltaTime)
{
// set color with i as alpha
img.color = new Color(1, 1, 1, i);
if (i <= 0.09)
{
fadeAway = false;
}
Debug.Log(i);
Debug.Log(fadeAway);
yield return null;
}
}
else
{
for (float i = 0; i <= 1; i += Time.deltaTime)
{
// set color with i as alpha
img.color = new Color(1, 1, 1, i);
if (i <= 9.8)
fadeAway = true;
Debug.Log(i);
yield return null;
}
}
}
}
잘됨
잘된다고?
친구야 두트윈쓰자...
두트윈이 뭐야
위의 적힌 페이드 인/아웃을 color.DoFade(0, 1f); // 1초만에 페이드아웃 color.DoFade(1, 1f); // 1초만에 페이드인 이거 두 줄로 땡치게 해주는 거. 에셋 스토어(DoTween)에서 받을 수 있고, 자세한건 두트윈으로 구글 같은데 검색해봐.
신기한게 많네
이게더 머리아파
https://gall.dcinside.com/mgallery/board/view/?id=game_dev&no=57572&_rk=CFQ&page=1
if (i <= 9.8)왜 9.8이냐?
0.98이구나
바꾸고 다시해봐
뭐가 안됨
꺼졌다가 안켜져
안켰잖아
fadeAway가 false로 바껴도 else 문으로는 안들어가질거임
왜안들어가져?
for문 끝나면 그대로 메서드 끝나잖아
왜 들어가져??
그렇네? 너네 천재다
수정했는데 이리해도 안대
IEnumerator Start() { yield return FadeImage(true); yield return FadeImage(false); }
void Start 함수를 이렇게 바꾸면 됨