How to start a dialogue when you walk up to a game object?

Amateur with Unity here. Just wondering how to make it so that when my character walks up to a particular game object, the dialogue will commence. I have already figured out how to create dialogue.

Thanks!

1 Answer

1

Part of the orginal post: You could add a box collider as trigger as a child of your character, and add another trigger to the gameobject that has the dialog.

Edit 2 (sortof):

I would put a dialogueinstance.js script on every person you should be able to talk to, and then remove the checkmark in front of "Dialogue Instance (Script)" in the inspector.

You will have to name your main character "Player" in the Hierarchy.

Add this script to every person you should be able to talk to: (and in the inspector, drag the "Dialogue Instance (Script)" to where it says "None (Dialogue Instance)"

var dialogue : DialogueInstance;
var endOnExit : boolean = true;
function OnTriggerEnter( collider1 : Collider )
{
    if ( collider1.name == "Player" )
        dialogue.enabled = true;
}

function OnTriggerExit( collider1 : Collider )
{
    if ( collider1.name == "Player" && endOnExit)
        dialogue.enabled = false;
}

"Then you could have a script running on the dialog game object, that looks something like this". On the game dialog object :)

How much scripting experience do you have? (just so I know how much I will need to explain) :)

Okay. In your Dialogueinstance script, can you see where the dialog is? You would then add the code that I posted to the Dialogueinstance script, and move the dialog to where it says //dialog. Is that comprehensible?

I'm gonna look at that other question sometime. But my bed is calling on me lol :) Editing my answer right now.

"then remove the checkmark in front of "Dialogue Instance (Script)" in the inspector." Are you sure that you have removed all the checkmarks in front of all the dialogueinstances?