대화창이 안꺼지고 대사가 무한 반복됩니다...

미해결질문
cancancan11 프로필
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class DialogManager : MonoBehaviour
{
    public static DialogManager instance;

    #region Singleton
    private void Awake()
    {
        if(instance == null)
        {
            DontDestroyOnLoad(this.gameObject);
            instance = this;
        }
        else
        {
            Destroy(this.gameObject);
        }
    }
    #endregion Singleton

    public Text text;
    public SpriteRenderer rendererDialogWindow;

    private List<stringlistSentences;
    private List<SpritelistDialogWindows;

    private int count;

    public Animator animDialogWindow;

    public bool talking = false
    private bool keyActivated = false;

    public Canvas ConCanvas;

        void Start()
        {
            count = 0;
            text.text ="";
            listSentences = new List<string>();
            listDialogWindows = new List<Sprite>();
        }

        public void ShowDialog(Dialog dialog)
        {
            talking = true;

            for(int i = 0i < dialog.sentences.Lengthi++)
            {
                listSentences.Add(dialog.sentences[i]);
                listDialogWindows.Add(dialog.dialogWindows[i]);
            }
            animDialogWindow.SetBool("Appear"true);
            StartCoroutine(StartDialogueCoroutine());
        }

        public void ExitDialogue()
        {
            text.text ="";
            count = 0;
            listSentences.Clear();
            listDialogWindows.Clear();
            animDialogWindow.SetBool("Appear"false);
            talking = false;
        }

        IEnumerator StartDialogueCoroutine()
        {
            if(count > 0)
                {
                    if(listDialogWindows[count] != listDialogWindows[count-1])
                {
                    animDialogWindow.SetBool("Appear"false);
                    yield return new WaitForSeconds(0.2f);
                    rendererDialogWindow.GetComponent<SpriteRenderer>().sprite = listDialogWindows[count];
                    animDialogWindow.SetBool("Appear"true);
                }
            }
            else
            {
                yield return new WaitForSeconds(0.05f);
                rendererDialogWindow.GetComponent<SpriteRenderer>().sprite = listDialogWindows[count];
            }
            keyActivated = true;
            for(int i = 0i < listSentences[count].Lengthi++)
                {
                    text.text += listSentences[count][i];
                    yield return new WaitForSeconds(0.01f);
                }
        }

        void Update()
        {
            if(talking && keyActivated)
            {
                if(Input.GetKeyDown(KeyCode.Z))
                {
                    keyActivated = false;
                    count++;
                    text.text ="";

                    if(count == listSentences.Count)
                    {
                        StopAllCoroutines();
                        ExitDialogue();
                        ConCanvas.enabled = false;
                    }
                    else
                    {
                        StopAllCoroutines();
                        StartCoroutine(StartDialogueCoroutine());
                    }
                }
            }
        }
}
코드에 문제가 있는건가요??
지식공유자 되기
많은 사람들에게 배움의 기회를 주고,
경제적 보상을 받아보세요.
지식공유참여
기업 교육을 위한 인프런
“인프런 비즈니스” 를 통해 모든 팀원이 인프런의 강의들을
자유롭게 학습하는 환경을 제공하세요.
인프런 비즈니스