Very simple dialogue Solutions

Hi,

Looking to create a simple dialogue script or popup that is triggered when the player walks up to an object (in this case, an animal model).

My team is having trouble figuring this out.

There aren’t a lot of steps or branches to the dialogue, just something along these lines:

  1. Player presses space bar on object
  2. Dialogue text (or image) displays.

(Optional) Any further dialouge is triggered by pressing spacebar.
First two are more important than the third.

I know there are several solutions to this (instantiating an image or guitext, for example) but I want to know the best or most efficient or most elegant way to go about doing this.

Thank you.

The simplest way that comes to mind is to have a dialogue behaviour which contains a list of strings and attach that on the object you want to interact with. The list of strings is the dialogue you want to display one after the other. It may also be the thing that handles the dialogue being displayed, using GUI or even other GUI packages you can get.

As for the interaction part of it. A simple trigger like interaction would be enough. When the player enters the trigger you can set a boolean value like “canSpeak” to true. You can even have a slot to set the dialogue behaviour on the player so you can control when you want the dialogue to be displayed.

public Dialogue dialogue;
public bool canSpeak;

void Update() {

// if the dialogue isn't displaying
if(dialogue  !dialogue.isDisplayed) {

// if the player can speak and they want to talk
if(canSpeak  Input.GetButtonDown("Talk") ) {

// display the dialogue
dialogue.Display();
}
}

}

The above is pretty simple (and incomplete). But you can it make so that every time you do “dialogue.Display()” it displays the next dialogue string until you reach the end of the list. There may need to some code in there to handle that. Like dialogue.Display() returning true to say the dialogue has reached the end or something.

Of course you’d need to build the dialogue behaviour to do all those things… but that’s part of the fun : D

Hope that helps.