대화창이 안꺼지고 대사가 무한 반복됩니다...
328
cancancan11
작성한 질문수 2
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<string> listSentences;
private List<Sprite> listDialogWindows;
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 = 0; i < dialog.sentences.Length; i++)
{
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 = 0; i < listSentences[count].Length; i++)
{
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());
}
}
}
}
}
코드에 문제가 있는건가요??
답변 0
ResourceManager 클래스 관련 질문
1
25
2
FBX chan 모델
0
18
1
첨부된 수업자료와 강의 내용이 다릅니다.
0
39
2
몬스터 HP 게이지바 이동
0
20
1
TextMeshPro용 커스텀 한글 2350자.txt 파일은 어디에 있나요?
0
22
1
02-02 NavMesh 응용 캐릭터 멈춤 문제
0
33
1
02-02 NavMesh 응용 캐릭터 멈춤 문제
0
41
2
C#에서의 RAII
0
64
3
Scene 뷰에서 Enemy Entity가 보이지 않는 문제
0
47
2
Lessons 3 & 4 don't have subtitles unfortunately
0
39
1
클로드코드 + 유니티 컨텐츠만들기 응용에 대하여 질문드립니다.
0
67
1
매니저 관련 질문이 있습니다.
0
69
2
맵이 어두워지는 현상
0
216
1
맥 OS환경에서도 만들 수 있나요?
0
281
1
자료구조도 사용하시나요?
0
314
1
코딩소스는 있는곳은없나요??
0
386
0
tiled로 unity 적용 할떄 자꾸 에러가 뜹니다
0
757
0
명령어가 안먹혀요///
0
336
1
tilde2unity가 안불러와져요
1
619
3
대화창에서 첫번째 문장이 안뜹니다
0
427
0
질문
1
472
1
scene이동시 객체 투명(?)화 현상..
0
303
1
걷다가 멈추면 캐릭터가 한쪽방향만 쳐다봐요 ㅠ
0
485
1
snap set 사용 질문이요
0
308
0





