我是Unity和C#的初学者,现在使用Unity和Vuforia实现10秒倒计时AR计时器。
我希望计时器在检测到标记后启动,但是现在计时器在检测到之前启动。
我也希望计时器在重新检测到标记后重置,但是现在计时器不会重置。
我想我应该在DefaultTrackableEventHandler.cs中更改OnTrackingFound()和OnTrackingLost()的一些代码,但是我不知道如何更改它。
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;
}
}
}
}