Fix dialogue box related bugs
This commit is contained in:
@@ -6,6 +6,9 @@ namespace Scampz.GameJam
|
||||
public class Dialogue
|
||||
{
|
||||
[TextArea(3, 10)]
|
||||
public string[] sentences;
|
||||
public string[] Sentences;
|
||||
|
||||
[SerializeField]
|
||||
public SFXClip SoundEffect;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,12 +9,13 @@ using UnityEngine;
|
||||
|
||||
namespace Scampz.GameJam
|
||||
{
|
||||
[RequireComponent(typeof(TextMeshProUGUI))]
|
||||
public class DialogueManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Animator _animator;
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI dialogueTextGUI;
|
||||
private TextMeshProUGUI _dialogueTextGUI;
|
||||
[SerializeField]
|
||||
private float _defaultTextSpeed = 0.1f;
|
||||
|
||||
@@ -56,13 +57,20 @@ namespace Scampz.GameJam
|
||||
_animator.SetBool("IsOpen", true);
|
||||
IsTalking = true;
|
||||
sentences.Clear();
|
||||
foreach (var sentence in dialogue.sentences)
|
||||
foreach (var sentence in dialogue.Sentences)
|
||||
sentences.Enqueue(sentence);
|
||||
|
||||
DisplayNextSentence();
|
||||
DisplayNextSentence(dialogue);
|
||||
}
|
||||
|
||||
public void DisplayNextSentence()
|
||||
private IEnumerator PlayAudioCoroutine(SFXClip soundEffect)
|
||||
{
|
||||
yield return null;
|
||||
SFXManager.Instance.PlaySoundEffect(soundEffect.audioClip.name);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
public void DisplayNextSentence(Dialogue dialogue)
|
||||
{
|
||||
if (!sentences.Any())
|
||||
{
|
||||
@@ -71,34 +79,33 @@ namespace Scampz.GameJam
|
||||
return;
|
||||
}
|
||||
|
||||
SFXManager.Instance.PlaySoundEffect(SoundEffectName.Narration);
|
||||
|
||||
var sentence = sentences.Dequeue();
|
||||
StopAllCoroutines();
|
||||
StartCoroutine(TypeSentence(sentence));
|
||||
StartCoroutine(TypeSentence(sentence, dialogue));
|
||||
StartCoroutine(nameof(PlayAudioCoroutine), dialogue.SoundEffect);
|
||||
}
|
||||
|
||||
private IEnumerator TypeSentence(string sentence)
|
||||
private IEnumerator TypeSentence(string sentence, Dialogue dialogue)
|
||||
{
|
||||
|
||||
dialogueTextGUI.text = string.Empty;
|
||||
_dialogueTextGUI.text = string.Empty;
|
||||
foreach (var letter in sentence.ToCharArray())
|
||||
{
|
||||
dialogueTextGUI.text += letter;
|
||||
_dialogueTextGUI.text += letter;
|
||||
yield return null;
|
||||
yield return new WaitForSeconds(_currentTextSpeed);
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds(1f);
|
||||
SFXManager.Instance.StopSoundEffect();
|
||||
yield return new WaitForKeyDown(InputOptions.Submit);
|
||||
SFXManager.Instance.PlaySoundEffect(SoundEffectName.Ok);
|
||||
DisplayNextSentence();
|
||||
DisplayNextSentence(dialogue);
|
||||
}
|
||||
|
||||
private void EndDialogue()
|
||||
{
|
||||
_animator.SetBool("IsOpen", false);
|
||||
_dialogueTextGUI.text = string.Empty;
|
||||
IsTalking = false;
|
||||
SFXManager.Instance.StopSoundEffect();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user