Implement dialogue system
This commit is contained in:
8
Assets/Scripts/Dialogue/DialogueInteraction.cs
Normal file
8
Assets/Scripts/Dialogue/DialogueInteraction.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Scampz.GameJam
|
||||
{
|
||||
public class DialogueInteraction : MonoBehaviour
|
||||
{
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Dialogue/DialogueInteraction.cs.meta
Normal file
11
Assets/Scripts/Dialogue/DialogueInteraction.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bd3e63ea94a97734bbe89a8d50059585
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,6 +1,8 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Scampz.GameJam.Assets.Scripts;
|
||||
using Scampz.GameJam.Assets.Scripts.Utilities;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -8,27 +10,28 @@ namespace Scampz.GameJam
|
||||
{
|
||||
public class DialogueManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Animator _animator;
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI dialogueTextGUI;
|
||||
public float TextSpeed = 0.1f;
|
||||
[SerializeField]
|
||||
private float _textSpeed = 0.1f;
|
||||
|
||||
public Queue<string> sentences;
|
||||
private Queue<string> sentences;
|
||||
|
||||
private static DialogueManager _instance;
|
||||
public static DialogueManager Instance;
|
||||
|
||||
public static DialogueManager Instance
|
||||
public bool IsTalking = false;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
get
|
||||
if (Instance != null && Instance != this)
|
||||
{
|
||||
if (!_instance)
|
||||
{
|
||||
_instance = new GameObject().AddComponent<DialogueManager>();
|
||||
_instance.name = _instance.GetType().ToString();
|
||||
DontDestroyOnLoad(_instance.gameObject);
|
||||
}
|
||||
|
||||
return _instance;
|
||||
Destroy(this);
|
||||
return;
|
||||
}
|
||||
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public void Start()
|
||||
@@ -36,8 +39,16 @@ namespace Scampz.GameJam
|
||||
sentences = new Queue<string>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (IsTalking && Input.GetButtonDown(InputOptions.Cancel))
|
||||
EndDialogue();
|
||||
}
|
||||
|
||||
public void StartDialogue(Dialogue dialogue)
|
||||
{
|
||||
_animator.SetBool("IsOpen", true);
|
||||
IsTalking = true;
|
||||
sentences.Clear();
|
||||
foreach (var sentence in dialogue.sentences)
|
||||
sentences.Enqueue(sentence);
|
||||
@@ -48,7 +59,10 @@ namespace Scampz.GameJam
|
||||
public void DisplayNextSentence()
|
||||
{
|
||||
if (!sentences.Any())
|
||||
{
|
||||
EndDialogue();
|
||||
return;
|
||||
}
|
||||
|
||||
var sentence = sentences.Dequeue();
|
||||
StopAllCoroutines();
|
||||
@@ -63,13 +77,17 @@ namespace Scampz.GameJam
|
||||
{
|
||||
dialogueTextGUI.text += letter;
|
||||
yield return null;
|
||||
yield return new WaitForSecondsRealtime(TextSpeed);
|
||||
yield return new WaitForSecondsRealtime(_textSpeed);
|
||||
}
|
||||
|
||||
yield return new WaitForKeyDown(InputOptions.Submit);
|
||||
DisplayNextSentence();
|
||||
}
|
||||
|
||||
private void EndDialogue()
|
||||
{
|
||||
// do nothing currently
|
||||
_animator.SetBool("IsOpen", false);
|
||||
IsTalking = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
37
Assets/Scripts/Dialogue/PromptDialogue.cs
Normal file
37
Assets/Scripts/Dialogue/PromptDialogue.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using Scampz.GameJam.Assets.Scripts;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Scampz.GameJam
|
||||
{
|
||||
public class PromptDialogue : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private DialogueTrigger _dialogueTrigger;
|
||||
|
||||
private bool _isWithinRange = false;
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.CompareTag("Player"))
|
||||
_isWithinRange = true;
|
||||
}
|
||||
|
||||
private void OnTriggerExit(Collider other)
|
||||
{
|
||||
if (other.CompareTag("Player"))
|
||||
_isWithinRange = false;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_isWithinRange && Input.GetButtonDown(InputOptions.Submit) && !DialogueManager.Instance.IsTalking)
|
||||
{
|
||||
var player = GameObject.FindGameObjectWithTag("Player");
|
||||
var cc = player.GetComponent<CharacterController>();
|
||||
cc.enabled = false;
|
||||
_dialogueTrigger.TriggerDialogue();
|
||||
cc.enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Dialogue/PromptDialogue.cs.meta
Normal file
11
Assets/Scripts/Dialogue/PromptDialogue.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 965133ab48042cf49acd1b0f8c2a2706
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user