대화창이 안꺼지고 대사가 무한 반복됩니다...
348
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());
}
}
}
}
}
코드에 문제가 있는건가요??
unity
回答 0
스크립트의 참조 설정
0
61
2
코드 스크립트 완성본 못 받나요 ?
0
84
2
'Canvas 설정과 배경 설정’ 부분에 대해 질문드립니다.
1
74
1
02-03 벽 마찰력 설정 material 적용 부분
0
67
1
영상이 안나옵니다. 그냥 빈공간이에요
1
106
3
layout group의 종류 3가지 실무 적합활용이 궁금합니다.
0
75
1
수박게임 자료 받았는데 plante05, 06이 없습니다.
0
74
1
14강 녹음이 안되어 있습니다
0
73
1
유니티webgl 과 안티그래비티를 협업시키고 싶습니다.
0
95
2
소스를 받을 수 있는 링크가 있을까요?
0
99
2
프로덕션 부분 사용 불가
0
104
2
접근지정자
0
95
2
맵이 어두워지는 현상
0
252
1
맥 OS환경에서도 만들 수 있나요?
0
319
1
자료구조도 사용하시나요?
0
349
1
코딩소스는 있는곳은없나요??
0
408
0
tiled로 unity 적용 할떄 자꾸 에러가 뜹니다
0
776
0
명령어가 안먹혀요///
0
371
1
tilde2unity가 안불러와져요
1
674
3
대화창에서 첫번째 문장이 안뜹니다
0
452
0
질문
1
496
1
scene이동시 객체 투명(?)화 현상..
0
323
1
걷다가 멈추면 캐릭터가 한쪽방향만 쳐다봐요 ㅠ
0
508
1
snap set 사용 질문이요
0
321
0

