OnTriggerEnter2D code

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
brolol07
Posts: 3
Joined: Tue Dec 01, 2015 11:38 pm

OnTriggerEnter2D code

Post by brolol07 »

Hello,

What do I put in the function to get it to activate my dialogue? Can it be done in 2D hopefully? Thanks, brolol07
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: OnTriggerEnter2D code

Post by Tony Li »

Hi,

First make sure your scene has a Dialogue Manager, and that you've assigned your dialogue database to the Dialogue Manager's Initial Database field. If you haven't done that yet, I recommend going through the 5-Minute Ultra-Quick Start tutorial.

Then just call DialogueManager.StartConversation. Provide the conversation's title and the transforms of the 2D characters:

Code: Select all

DialogueManager.StartConversation("My Conversation", player.transform, someNPC.transform);
The transforms are optional, but they let you use the keywords 'speaker' and 'listener' in sequencer commands.

Or you can use a Conversation Trigger or other trigger component as described in How to Set Up NPCs. If you still want to start it manually from code, you can set the trigger to OnUse and send an "OnUse" message to it:

Code: Select all

var triggerObject = GameObject.Find("MyConversationTriggerGameObject");
triggerObject.SendMessage("OnUse");
Post Reply