A way to add an exit button, like the next button

At the end of the dialogue, if you want to exit with a button as the next button, do this:
In the Dialogue Prefab in unity, duplicate the Button Row and rename it as you want (for me Button Row Exit)
Always with the Button Row Exit selected, tweak is top position in its vertical layout to overlap the next button:
Change the button’s text field to “Exit” or “Quit” or whatever you want :wink:
You must have something like that, depending of your UI design, with the Exit button overlapping the next Button:

Open your DialogueUI.cs script and add a reference to your exitButton and an exitButton.Onclick event like that for me:

        [SerializeField] Button quitCross;
        [SerializeField] Button exitButton;//New ref to add for the exit button

        // Start is called before the first frame update
        void Start()
            playerConversant = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerConversant>();
            playerConversant.onConversationUpdate += UpdateUI;
            nextButton.onClick.AddListener(() => playerConversant.Next());
            quitCross.onClick.AddListener(() => playerConversant.Quit());
            exitButton.onClick.AddListener(() => playerConversant.Quit());// New line to add for the Exit Button


(I have comment the 2 new lines)

Then in the UpdateUI() methode add this at the end:

                AIText.text = playerConversant.GetText();
                exitButton.gameObject.SetActive(false);//For exit bouton
                exitButton.gameObject.SetActive(true);//For exit bouton

The first line added is to hide the Exit Button as long as there id dialogue option.
( exitButton.gameObject.SetActive(false);//For exit bouton)

The new if test is used to activate your new exit button only when there isn’t any dialogue option.

Save and go in Unity to add the Exit Button in the Dialogue field:

It’s the end of the dialogue and when you will clic this button, the event add at the start will close the discussion panel.
Hoping it helps.



Privacy & Terms