By kageori
on Mon, 07/15/2019 - 11:00
I am a beginner of Unity and C# and now implementing the 10 second countdown AR timer using Unity and Vuforia.
What I want to implement is:
- Start the timer when the target has detected
- Reset the timer when the target has removed
However in my code the timer starts before detection and does not reset.
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 can help me.
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(); 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; } } } }