Capture time and display on a new panel

Announcements, support questions, and discussion for Quest Machine.
Post Reply
Mchia_Soo
Posts: 72
Joined: Sun Jun 30, 2019 11:59 pm

Capture time and display on a new panel

Post by Mchia_Soo »

Hey there! Hope you have a nice day ahead!

I have a question here. Is there any way to display the time consumed on the panel?

There is a counter I set for the countdown in Quest Machine. I have tried using the script to display, but I do not know what's wrong with my script. :?

Here is my code:

Code: Select all

    public Text timerText;
    private float startTime;
    public QuestState newState;
    
    void Start(){
        startTime = Time.time;
    }

    void CaptureTime (){
        string minutes;

        if (newState == QuestState.Active){
            Debug.Log("1");
            float t = Time.time - startTime;
            minutes = ((int)t / 60).ToString("00");
            string seconds = (t % 60).ToString("00");
            timerText.text = minutes + ":" + seconds;
        }
    }

    void Update(){
        CaptureTime();
    }
Other than using the script, do you have other suggestion which is easier for me as I'm not good at coding?

Thanks for your time and sorry if troubling you.
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Capture time and display on a new panel

Post by Tony Li »

Hi,

Are you talking about a countdown timer on a quest?

If so, please look at the Demo scene's Coin Race quest. The pirate NPC gives this quest. When you start the quest, the quest HUD shows the countdown.
Mchia_Soo
Posts: 72
Joined: Sun Jun 30, 2019 11:59 pm

Re: Capture time and display on a new panel

Post by Mchia_Soo »

Yes, it is the countdown timer.

However the one I want to display is not the countdown one, it's the time spent when the mission is active. For example in the panel, Time Spent: 1m30s (the word I want to display).
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Capture time and display on a new panel

Post by Tony Li »

Hi,

Make a custom quest content type. Copy QuestContentTemplate.cs -- for example, name it TimeQuestContent.cs. Follow the comments to add your code.

The HUD Text (or Journal Text) dropdown menu will then include TimeQuestContent. Add it where you want to show the time.
Mchia_Soo
Posts: 72
Joined: Sun Jun 30, 2019 11:59 pm

Re: Capture time and display on a new panel

Post by Mchia_Soo »

Alright, will try it! Thanks again!!
Post Reply