[HOWTO] How To: Write Custom Quest Action To Start Dialogue
Posted: Tue Feb 06, 2024 9:56 am
Here's a custom quest action that tells a Quest Giver to open the quest dialogue UI onto the current quest:
StartDialogueQuestAction.cs
StartDialogueQuestAction.cs
Code: Select all
using UnityEngine;
using PixelCrushers;
using PixelCrushers.QuestMachine;
public class StartDialogueQuestAction : QuestAction
{
public StringField questGiverID;
public override void Execute()
{
base.Execute();
var go = QuestMachineMessages.FindGameObjectWithID(questGiverID);
var questGiver = (go != null) ? go.GetComponent<QuestGiver>() : null;
if (questGiver != null)
{
questGiver.StartSpecifiedQuestDialogueWithPlayer(StringField.GetStringValue(quest.id));
}
else
{
Debug.LogWarning($"Can't locate Quest Giver '{questGiverID}' to start dialogue");
}
}
}