7cea8577bd826ff736e698b21fd704031cbebdd48c66e2385f4955



    public Sprite[] playerImage; // 플레이어 스토리 일러스트

    public Sprite[] NPCImage; // NPC 스토리 일러스트

    public string[] story0_Name; // 0 첫 대화 & 튜토리얼

    public string[] story0_Comment; 

    public int chapterother; // 현재 진행중인 챕터

    public int lineOrder; // 대화 라인


    public Text dialogText; // 대화창에 사용할 UI Text

    public AudioSource audioSource; // 글자마다 재생할 AudioSource

    public AudioClip typeSound; // 타이핑 소리


    private string fullText; // 출력할 전체 텍스트

    private string currentText = ""; // 현재 출력 중인 텍스트


    public float typingSpeed = 0.05f; // 글자 출력 간격 (초)

    private Coroutine typingCoroutine; // 현재 실행 중인 코루틴 참조


    private bool isTyping = false; // 타이핑 중인지 확인


    [SerializeField] Text nameText; // 이름 출력용 UI Text

    [SerializeField] Text commentText; // 코멘트 출력용 UI Text


   // 대화창 텍스트를 설정하고 타이핑 효과 시작

   public void StartTyping(string text)

   {

       ImageLine();

       fullText = text; // 전체 출력할 텍스트 설정

       currentText = ""; // 현재 출력 중인 텍스트 초기화

       dialogText.text = ""; // 대화창 텍스트를 비움

       isTyping = true; // 타이핑 상태를 활성화


       // 기존에 실행 중인 코루틴이 있으면 중지

       if (typingCoroutine != null)

       {

           StopCoroutine(typingCoroutine);

       }


       // 새로운 코루틴 시작

       if (lineOrder <= story0_Name.Length)

       {

           typingCoroutine = StartCoroutine(TypeText());

       }

       else

       {

           StoryWindow.SetActive(false);

       }

   }


   // 텍스트를 한 글자씩 출력하는 코루틴

   private IEnumerator TypeText()

   {

       for (int i = 0; i < fullText.Length; i++) // 전체 텍스트의 각 글자에 대해 반복

       {

           currentText += fullText[i]; // 한 글자를 현재 텍스트에 추가

           dialogText.text = currentText; // 대화창에 현재 텍스트를 표시


           // 글자 5번당 한 번씩 소리 재생

           if (i % 2 == 0) // i가 2로 나누어 떨어질 때

           {

               (AudioManager.sfx3.TalkSound);

           }


           yield return new WaitForSeconds(typingSpeed); // 다음 글자 출력 전 대기

       }


       isTyping = false; // 모든 글자 출력이 완료되면 타이핑 상태 해제

   }


   // 대화창 클릭 시 호출되는 메서드

   public void OnDialogClick()

   {

       if (isTyping) // 타이핑 중이라면

       {

           StopCoroutine(typingCoroutine); // 코루틴 중지

           dialogText.text = fullText; // 전체 텍스트를 한 번에 출력

           isTyping = false; // 타이핑 상태 해제

       }

       else

       {

           lineOrder += 1;

           if (lineOrder < story0_Comment.Length)

           {

               StartTyping(commentText.text = story0_Comment[lineOrder]);

           }

           else

           {

               StoryWindow.SetActive(false);

           }

       }

   } 


ImageLine()은 대화 할 때 뜨는 캐릭터나 대화창 관리하는 거 아무래도 대화 할 때 표정이나 포즈나


대화창 모양도 다르게 구현해야 해서 이미지 매니저로 관리를 넘겨서 업데이트로 불러오기만 함