inflearn logo
강의

Khóa học

Chia sẻ kiến thức

Khóa học Unity [Tạo trò chơi theo phong cách Tsukur]

Sự Kiện (2) - Hệ Thống Đối Thoại

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

328

cancancan11

2 câu hỏi đã được viết

0

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());
                    }
                }
            }
        }
}
코드에 문제가 있는건가요??

unity

Câu trả lời 0

5강, 오류 수정과 관련해서

0

17

2

컴퓨터를 껐다가 클로드 코드 다시 키는 방법 알려주세요.

0

16

1

MA-POCA 알고리즘 응용 질문

0

15

1

Pivot을 마우스로 클릭하고 드래그해도 움직이 않아서 혹시 아시는 부분이 있나 해서 문의 남깁니다.

0

17

1

카메라가 많아지면 렌더링 비용이 커지나요?

0

28

1

3:56에 폰트 불러온 과정이 궁금합니다 ㅠㅠ

0

41

3

Spider와 Monster 구현 방식을 구분한 이유

1

25

1

Sprute Sheet에 대해서.

0

36

1

ResourceManager 클래스 관련 질문

1

43

2

FBX chan 모델

0

28

1

첨부된 수업자료와 강의 내용이 다릅니다.

0

69

2

몬스터 HP 게이지바 이동

0

24

1

맵이 어두워지는 현상

0

218

1

맥 OS환경에서도 만들 수 있나요?

0

281

1

자료구조도 사용하시나요?

0

314

1

코딩소스는 있는곳은없나요??

0

388

0

tiled로 unity 적용 할떄 자꾸 에러가 뜹니다

0

757

0

명령어가 안먹혀요///

0

336

1

tilde2unity가 안불러와져요

1

625

3

대화창에서 첫번째 문장이 안뜹니다

0

429

0

질문

1

474

1

scene이동시 객체 투명(?)화 현상..

0

304

1

걷다가 멈추면 캐릭터가 한쪽방향만 쳐다봐요 ㅠ

0

487

1

snap set 사용 질문이요

0

310

0