Show Quest Log by Pressing Button

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Arctichorse9
Posts: 25
Joined: Wed Sep 25, 2024 11:26 pm
Location: New York City
Contact:

Show Quest Log by Pressing Button

Post by Arctichorse9 »

Hi. I can't seem to get this to work.

I have the Dialogue Manager in the first scene--Main Menu--as I read it should only be in one scene and if I put it in every scene I have some problems.

So I don't know where to put the Quest Log UI prefab in each scene. I put it in as a prefab that's hidden and added a hotkey to the button to show it when you press the button but nothing happens.

Any help is appreciated. Thanks. I don't want to show it by pressing a button in the Pause Menu but by pressing a book icon button at the top of the screen.
User avatar
Tony Li
Posts: 22093
Joined: Thu Jul 18, 2013 1:27 pm

Re: Show Quest Log by Pressing Button

Post by Tony Li »

Hi,

You only need a single quest log window, typically as a child of the Dialogue Manager's Canvas (or any canvas that's a child of the Dialogue Manager). You can add it manually, or you can let the Dialogue Manager's Instantiate Prefabs component instantiate it as a child.

If you want to open it with a hotkey input, add a QuestLogWindowHotkey anywhere. You can put it individually in each scene, or just once on the Dialogue Manager.

If you want to open it with a UI Button, add a script like this to the UI Button:

OpenQuestLogWindowOnClick.cs

Code: Select all

using UnityEngine;
using UnityEngine.UI;
using PixelCrushers.DialogueSystem;
[RequireComponent(typeof(Button))]
public class OpenQuestLogWindowOnClick : MonoBehaviour
{
    private void Start()
    {
        GetComponent<Button>().onClick.AddListener(() =>
        {
            DialogueManager.instance.GetComponentInChildren<QuestLogWindow>().Open();
        });
    }
}
You don't have to configure the Button's OnClick() event. The script will handle it.
Arctichorse9
Posts: 25
Joined: Wed Sep 25, 2024 11:26 pm
Location: New York City
Contact:

Re: Show Quest Log by Pressing Button

Post by Arctichorse9 »

Hi. I am having a little bit of trouble with this code.

Is the ); after the first closing bracket intentional?

Would it be possible for you to put up the code without the lambda expression?

Thanks very much.
User avatar
Tony Li
Posts: 22093
Joined: Thu Jul 18, 2013 1:27 pm

Re: Show Quest Log by Pressing Button

Post by Tony Li »

Hi,

The problem is almost certainly elsewhere, but here you go:

Code: Select all

using UnityEngine;
using UnityEngine.UI;
using PixelCrushers.DialogueSystem;
[RequireComponent(typeof(Button))]
public class OpenQuestLogWindowOnClick : MonoBehaviour
{
    private void Start()
    {
        GetComponent<Button>().onClick.AddListener(OpenQuestLogWindow);
    }

    private void OpenQuestLogWindow()
    {
        DialogueManager.instance.GetComponentInChildren<QuestLogWindow>().Open();
    }
}
What isn't working?
Arctichorse9
Posts: 25
Joined: Wed Sep 25, 2024 11:26 pm
Location: New York City
Contact:

Re: Show Quest Log by Pressing Button

Post by Arctichorse9 »

That script works perfectly. Thank you very much.

And today the first script works perfectly. Yesterday I got an error message about a delegate so I must have typed something wrong. And I don't know enough about Lambda expressions to know what it might have been.
Learning.

Thanks so much. It's perfect.

I have Dialogue System, Quest Machine, Love/Hate and looking at Grid Controller. But need to learn those first. I'm trying to read the forum so I don't have to ask so many questions. Have a little rest and thank you. : )
User avatar
Tony Li
Posts: 22093
Joined: Thu Jul 18, 2013 1:27 pm

Re: Show Quest Log by Pressing Button

Post by Tony Li »

Glad to help!

Tip: Search for "howto" (one word) plus a question for helpful how-to articles. If you don't find an answer after a quick search, please feel free to ask. I'm here to help!
Post Reply