Unity

[Unity] 패널값 조정으로 글자 깜빡깜빡

시카Dev 2024. 1. 12. 00:48

사용자가 게임을 다 하고나서 완료! 화면이 뜨고, 하단에 '터치하면 다음 스테이지로 이동합니다' 라는 문구가 뜰때 사용하면 좋을 것 같음. 사용자의 터치 전까지는 하단 문구가 계속해서 깜빡거리는...?
 
계속해서 깜빡거린다는 것이 어찌보면 그것도 반복 작업이니까, 코루틴을 사용했다
-> 페이드인/페이드 아웃을 계속해서 반복시키면 된다
방법은 오브젝트의 알파값을 조정하는데, 이때 알파가 255이면 뚜렷히 오브젝트가 보이고 0이면 아예 안보인다
 
글고 코루틴 안에서 코루틴 사용 가능하다는 것을 깨달았다
 
 
 
    IEnumerator Fadeout() //페이드아웃
    {
        float alpha = 0;
        while (alpha < 0.8f)
        {
            alpha += 0.005f;
            image.color = new Color(0, 0, 0, alpha);
            yield return null;
        }
            text.gameObject.SetActive(true);  //패널값을 조정할 텍스트
            StartCoroutine(FadeTextToFull()); //텍스트 깜빡거리기

    }



    public IEnumerator FadeTextToFull() // 알파값 0에서 1로 전환
    {
        text.color = new Color(text.color.r, text.color.g, text.color.b, 0);
        while (text.color.a < 1.0f)
        {
            text.color = new Color(text.color.r, text.color.g, text.color.b, text.color.a + 0.02f);
            yield return null;
        }
        StartCoroutine(FadeTextToZero());
    }

    public IEnumerator FadeTextToZero()  // 알파값 1에서 0으로 전환
    {
        text.color = new Color(text.color.r, text.color.g, text.color.b, 1);
        while (text.color.a > 0.0f)
        {
            text.color = new Color(text.color.r, text.color.g, text.color.b, text.color.a - 0.02f);
            yield return null;
        }
        StartCoroutine(FadeTextToFull());
    }


 
 
이렇게 하면 FadeTextToFull()에서 FadeTextToZero()으로 계속 왔다갔다 하게 된다.
 
 
 

<페이드인>
IEnumerator FadeIn()
    {
        float alpha = 1.0f;
        while (alpha > 0.0f)
        {
            alpha -= 0.03f;
            image.color = new Color(0, 0, 0, alpha);
            yield return null;
        }
        image.gameObject.SetActive(false);
    }

 
추가적으로 이건 페이드인 코드..
 
 
 
인턴할때 사용했던 기능들인데 글씨 연출하는데 사용했었당