728x90

 

문제점: 한 글자씩 타이핑 줄때 <color~ 같은 태그가 유저에게 보인다. </color> 까지 닫아줘야 색상이 지정된다.
해결: 임시 제어문자를 넣어준다. 

 


    string testStr = "안녕하세요. r거두절meb입니다.";

    public IEnumerator ShowText(string fullText, Text txtCompo)
    {
        string displayText = ""; // 표시할 최종 문자열
        string color = "black"; // 기본 색상

        for (int i = 0; i < fullText.Length; i++)
        {
            if(fullText[i] == 'r'){
                color = "red"; // 빨간색 설정
                continue;
            } else if(fullText[i] == 'b'){
                color = "black"; // 검정색 설정
                continue;
            }

            // 현재 문자에 적절한 색상 적용
            displayText += $"<color={color}>{fullText[i]}</color>";

            txtCompo.text = displayText;
            yield return new WaitForSeconds(0.1f);
        }

        juniorScriptCoroutine = null;
    }

 

사용법: r, b는 내가 넣은 임시 문자고 필요에 따라 다른걸 넣어주면 된다.
r뒤부터는 빨간색이 나오고, b뒤부터는 검정색이 나올 수 있도록했다. 
r, b 차례일때는 다음 폰트의 color만 바꿔주는 역할만 하고 텍스트에 들어가지 않도록 continue를 해준다.

 

 

728x90
반응형

+ Recent posts