Page 1 of 1
Show Quest Log by Pressing Button
Posted: Sun Nov 10, 2024 8:15 pm
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.
Re: Show Quest Log by Pressing Button
Posted: Sun Nov 10, 2024 9:01 pm
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.
Re: Show Quest Log by Pressing Button
Posted: Mon Nov 11, 2024 2:38 pm
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.
Re: Show Quest Log by Pressing Button
Posted: Mon Nov 11, 2024 3:37 pm
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?
Re: Show Quest Log by Pressing Button
Posted: Mon Nov 11, 2024 9:59 pm
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. : )
Re: Show Quest Log by Pressing Button
Posted: Tue Nov 12, 2024 6:39 am
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!