Log in or register to post comments

How to toggle count down timer during the marker is detected?

July 14, 2019 - 5:52am #1

I am very beginner of Unity and C# and now implementing the 10 second count down AR timer using Unity and Vuforia.

 

What I hope to do is:

- Start the count down timer when the target has detected

- Reset the timer when the target has not detected

 

However,  now the timer starts before the target is detected and does not reset when it is detected again.

I suppose I should change some code of OnTrackingFound() and OnTrackingLost() in DefaultTrackableEventHandler.cs, but I have no idea how to change it.

I'm glad if you help me.

 

The following is my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class TimeScript : MonoBehaviour {
    public GameObject time_object = null;
    private int time_num = 10;
    float TimeCount  = 1;
    // Start is called before the first frame update
    void Start () {

    }

    // Update is called once per frame
    void Update () {
        Text time_text = time_object.GetComponent<Text> ();
        time_text.text = "00:" + string.Format ("{0:00}", time_num);
        TimeCount -= Time.deltaTime;

        if (TimeCount <= 0) {
            time_num -= 1;
            TimeCount = 1;
            if (time_num == -1) {
                enabled = false;
            }
        }

    }
}
Log in or register to post comments