Implement Button to open DialogueUI

Hey hello,

I am currently following the Unity Dialogue & Quest course, still a bit of a beginner. In the lecture you can open the dialog when pressing the mouse button. However am making a game on mobile and want to implement a UI Button where the player can click to talk on.

However I currently have not found a solution on how to implement the button to open the dialogue. The transparent white box is the button this is the code:

PlayerConversant playerConversant;

public bool OpenDialagueButton(PlayerController callingController)
{

        dialogueButton.onClick.AddListener(() =>
        {
            callingController.GetComponent<PlayerConversant>().StartDialogue(dialogue);
        });

        return true;
    }

PlayerConversant is from another file this is this code that needs to trigger:

    public void StartDialogue(Dialogue newDialogue)
    {
        currentDialogue = newDialogue;
        currentNode = currentDialogue.GetRootNode();
        onConversationUpdated();
    }

I’m not entirely sure buttons will work this way in a scene.

On the other hand, the IPointerClickHandler may be the way to go here:

So the idea here is you would add the interface to your AIConversant, and implement the OnPointerClick() method. This will be called when the character is clicked. At that point, call the PlayerConversant to start the dialogue.

Privacy & Terms