Please check out this DialogueTrigger.cs
Read the comments and PLEASE
correct me where I am wrong
Thanks!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
namespace RPG.Dialogue
{
public class DialogueTrigger : MonoBehaviour
{
// The purpose of this script is to allow user to add an action to any gameObject
// (currently a string that can be used to MATCH the dialogue Nodes (onEnterAction or onExitAction) events
// I plan on changing this to an enum)
// this allows the designer(user) to choose from Unity drop down of
// functions to call based on gameObject dragged into it (that unity event from Inspector)
// (can also be this object -- meaning the one this script is on)
//
// In our class we added it(this script) to Enemy 6 in inspector
// In our dialogue I added Attack to the onEnterAction of the last node (of the wrong path made guard angry)
// On Enemy 6 Hit plus sign drug Enemies Parent into Game Object (it has a Aggro Group script
// to activate all enemies attack again)
// Hit plus to add another event
// drug Player into game object slot
// choose PlayerConversant.Quit to close the dialogue
[SerializeField] string actionFromDialogueNode; // Makes it clearer to my designer
[SerializeField] UnityEvent onTrigger;
public void Trigger(string actionToTrigger)
{
// Seems like actionThatTriggers would be a better name here
// am i correct in thinking the string name only has to match
// the DialogueNode and the string the designer enters in this component(actionFromDialogueNode)??????
// if they match then the unity event onTrigger will fire
// based on the gameObject that the Designer pulled into this component??
// Thanks for helping me understand
if (actionToTrigger == actionFromDialogueNode)
{
onTrigger?.Invoke(); // This will invoke the selected unity click event from Inspector
}
}
}
}
Thanks for your help