Page 1 of 1

Capture time and display on a new panel

Posted: Mon Oct 07, 2019 9:37 am
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.

Re: Capture time and display on a new panel

Posted: Mon Oct 07, 2019 10:13 am
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.

Re: Capture time and display on a new panel

Posted: Mon Oct 07, 2019 10:28 am
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).

Re: Capture time and display on a new panel

Posted: Mon Oct 07, 2019 11:35 am
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.

Re: Capture time and display on a new panel

Posted: Mon Oct 07, 2019 11:52 am
by Mchia_Soo
Alright, will try it! Thanks again!!