[HELP] Clear HUD

Announcements, support questions, and discussion for Quest Machine.
Post Reply
mschoenhals
Posts: 118
Joined: Thu Dec 19, 2019 7:38 am

[HELP] Clear HUD

Post by mschoenhals »

Hi,
I would like to clear the HUD when the player quits to main menu. Right now, main menu will show current HUD status if the player goes back into the main menu after getting a quest. Is there a simple way to clear the HUD?

Thank you in advance.
User avatar
Tony Li
Posts: 21722
Joined: Thu Jul 18, 2013 1:27 pm

Re: [HELP] Clear HUD

Post by Tony Li »

Hi,

Call the quest HUD's Hide() method to hide it, and Show() to show it again.

For example, in the main menu you could add a script like this:

Code: Select all

using UnityEngine;
using PixelCrushers.QuestMachine;

public class HideHUDInMainMenu : MonoBehaviour
{
    void OnStart() // Hide HUD when main menu starts.
    {
        QuestMachine.defaultQuestHUD.Hide();
    }
    
    void OnDestroy() // When leaving this scene (e.g., to gameplay scene), show HUD.
    {
        QuestMachine.defaultQuestHUD.Show();
    }
}
mschoenhals
Posts: 118
Joined: Thu Dec 19, 2019 7:38 am

Re: [HELP] Clear HUD

Post by mschoenhals »

Thanks for your response Tony. It looks like Show requires some parameters:

Code: Select all

        void Show(QuestListContainer questListContainer);
I also see there is a Toggle, but it requires parameters as well. What are the parameters then to include for Show or Toggle?
User avatar
Tony Li
Posts: 21722
Joined: Thu Jul 18, 2013 1:27 pm

Re: [HELP] Clear HUD

Post by Tony Li »

Hi,

There's also a version of Show() that doesn't require a parameter.

However, it might be clearer in the long run to split it into two scripts. Two separate scripts make it clearer to know what's going on.

In the main menu scene, add this script:

HideHUD.cs

Code: Select all

using UnityEngine;
using PixelCrushers.QuestMachine;

public class HideHUD : MonoBehaviour
{
    void Start() // Hide HUD when (main menu) scene starts.
    {
        QuestMachine.defaultQuestHUD.Hide();
    }
}
On your player (in the gameplay scenes), add this script:

ShowHUD.cs

Code: Select all

using UnityEngine;
using PixelCrushers.QuestMachine;

[RequireComponent(typeof(QuestJournal))]
public class ShowHUD : MonoBehaviour
{
    void Start() // Show HUD when (gameplay) scene starts.
    {
        QuestMachine.defaultQuestHUD.Show(GetComponent<QuestJournal>());
    }
}
mschoenhals
Posts: 118
Joined: Thu Dec 19, 2019 7:38 am

Re: [HELP] Clear HUD

Post by mschoenhals »

Hi Tony,

That worked really well, thank you. Would it be possible to do something similar for the Dialogue System? If a player dies or ends game during a dialogue, the dialogue window stays on screen. Is it possible to handle it in the same scripts?

Thank you in advance.
User avatar
Tony Li
Posts: 21722
Joined: Thu Jul 18, 2013 1:27 pm

Re: [HELP] Clear HUD

Post by Tony Li »

Yes, in the same HideHUD script call:

Code: Select all

PixelCrushers.DialogueSystem.DialogueManager.StopConversation();
Post Reply