-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changed to new dialogue system (breaks the old dialogue!)
- Loading branch information
Showing
3 changed files
with
91 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,31 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using DialogueSystem; | ||
|
||
|
||
[System.Serializable] | ||
public class MessagePair { | ||
public string Character; | ||
[TextArea] | ||
public string Message; | ||
} | ||
|
||
[System.Serializable] | ||
public class DialogueTrigger : MonoBehaviour | ||
{ | ||
// Start is called before the first frame update | ||
public List<MessagePair> Messages; | ||
public Dialogue Dialogue; | ||
|
||
public int MaxOccurrences = 1; | ||
private int Occurrences = 0; | ||
void Start() | ||
{ | ||
gameObject.GetComponent<MeshRenderer>().enabled = false; | ||
} | ||
|
||
// Update is called once per frame | ||
void Update() | ||
{ | ||
|
||
} | ||
|
||
/// <summary> | ||
/// If the player collides with this trigger, start a dialogue sequence. | ||
/// </summary> | ||
/// <param name="other">The other Collider involved in this collision.</param> | ||
void OnTriggerEnter(Collider other) | ||
{ | ||
if (other.tag == "Player" && Occurrences < MaxOccurrences) { | ||
var dialogueManager = other.GetComponent<DialogueManager>(); | ||
if (!dialogueManager.IsOpen) { | ||
Occurrences++; | ||
StartCoroutine(RunThroughDialogue(dialogueManager)); | ||
} | ||
} | ||
} | ||
|
||
IEnumerator RunThroughDialogue(DialogueManager dialogueManager) { | ||
foreach (var message in Messages) { | ||
yield return dialogueManager.Write(message.Message, message.Character); | ||
if (other.tag == "Player" && Occurrences < MaxOccurrences) | ||
{ | ||
other.GetComponent<DialogueManager>()?.AddToQueue(Dialogue.Clone()); | ||
} | ||
} | ||
} |