오늘도 돌아온... 디버그해줘 빼액 시간임.


오늘은 그래도 하다가 막힌거라, 내 코드가 재활용 불가 쓰레기통에 들어가야 할 수준의 졸작만 아니라면 그래도 너희 입장에선 쉽지 않을까 싶은데.


만들고 싶은 건 이거임.




저 말풍선 클릭하면 0.5초간 사라지는 거 있지? 저걸 만들거임. 


아니... 정확히는 만들어야 했지.


내가 짠 코드인데, 이상하게 작동을 안 하네. 어디서부터 틀린 건지 좀 알려줘


using UnityEngine;

using UnityEngine.UI;

using System.Collections;

using TMPro;


public class Text_inv : MonoBehaviour

{

    public Image imageToFade;

    public TextMeshProUGUI[] textsToFade;

    public float fadeDuration = 1f;


    private bool isFading = false;


    void Update()

    {


        if ((Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.Space)) && !isFading)

        {

            isFading = true;

            StartCoroutine(FadeOutAndShow());

        }

    }


    IEnumerator FadeOutAndShow()

    {

        float timer = 0f;

        Color targetColor = new Color(1f, 1f, 1f, 0f);

        Color[] initialColors = new Color[textsToFade.Length];


     

        for (int i = 0; i < textsToFade.Length; i++)

        {

            initialColors[i] = textsToFade[i].color;

        }


        while (timer < fadeDuration)

        {

            timer += Time.deltaTime;

            float ratio = timer / fadeDuration;


            imageToFade.color = Color.Lerp(Color.white, targetColor, ratio);


            // 각 텍스트에 대해 초기 색상 사용

            for (int i = 0; i < textsToFade.Length; i++)

            {

                textsToFade[i].color = Color.Lerp(initialColors[i], targetColor, ratio);

            }


            yield return null;

        }


        imageToFade.gameObject.SetActive(false);

        foreach (TextMeshProUGUI text in textsToFade)

        {

            text.gameObject.SetActive(false);

        }


        yield return new WaitUntil(() => Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.Space));


        imageToFade.gameObject.SetActive(true);

        foreach (TextMeshProUGUI text in textsToFade)

        {

            text.gameObject.SetActive(true);

            text.color = initialColors[0];

        }


        isFading = false;

    }

}




참고로 할당 문제 아닌 거 확인했고, 텍스트 출력하는 스크립트 자체는 따로 완성시켜뒀음.



그럼 이번에도...