我已经研究了如何制作倒数计时器。我想制作一个计时器来计算我在检查器中指定的分钟和秒数。当我点击一个对象时,计时器会减少几分钟和/或几秒钟。我稍后会做出决定。下面是我的代码。谢谢!
using UnityEngine;
using System.Collections;
public class controllerScript : MonoBehaviour {
public GUIText timerText;
public float minutes;
void Start(){
timerText.text = "";
}
void Update(){
if (Input.GetMouseButtonDown(0)){
Debug.Log("pressed left click, casting ray");
CastRay();
}
minutes -= Time.deltaTime;
timerText.text = minutes.ToString("f0") + "";
}
void CastRay(){
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit2D hit = Physics2D.Raycast (ray.origin, ray.direction, Mathf.Infinity);
//start statements for what happens when Objects are clicked
if (hit.collider.gameObject.name == "target01"){
Debug.Log("you've click obj 1, good work.");
}
if (hit.collider.gameObject.name == "target02"){
Debug.Log("well that's obj 2, even better!");
}
}
}
答案 0 :(得分:3)
不知道,你的问题究竟是什么, 但你应该意识到,Time.deltaTime是以秒为单位的时间,而不是几分钟。
所以你应该改变这一行
minutes -= Time.deltaTime;
到
minutes -= Time.deltaTime / 60.0;