Add a dialogue system trigger in code and start a conversation onuse
Posted: Wed Jul 03, 2024 7:19 am
Add a dialogue system trigger in code and start a conversation onuse.
I have a random npc character the is generated through code (at runtime), so I need to add a dialoguesystemtrigger , as a component at runtime.
eg.
But I'm not sure how to add a "start conversation" action in code.
I have a random npc character the is generated through code (at runtime), so I need to add a dialoguesystemtrigger , as a component at runtime.
eg.
Code: Select all
if (addDialogueSystemTriggers)
{
DialogueSystemTrigger dialogueSystemTrigger = BaseCharacterInstance.AddComponent<DialogueSystemTrigger>();
if (Godject.Instance.simplePlayerController != null)
{
dialogueSystemTrigger.conversationActor = Godject.Instance.simplePlayerController.transform;
}
dialogueSystemTrigger.conversationConversant = BaseCharacterInstance.transform;
dialogueSystemTrigger.conversation = conversation;
Usable usable = BaseCharacterInstance.AddComponent<Usable>();
usable.maxUseDistance = 2.0f;
DialogueSystemEvents dialogueSystemEvent = BaseCharacterInstance.AddComponent<DialogueSystemEvents>();
}