我正在尝试扩展这个滚球教程以包含一个计时器,并允许用户通过点击触摸板来重试,无论他们赢了还是时间用完了。
如果时间用完(// case A
下),但如果玩家获胜(// case B
下),这将按预期工作,因为水龙头似乎没有被识别。在这两种情况下都会出现结束消息,因此它肯定会到达这些部分,但我猜该程序没有到达带有评论的部分,// reset on tap
但不确定。
任何想法表示赞赏。
我的PlayerController
脚本:
void Start ()
{
timeLeft = 5;
rb = GetComponent<Rigidbody>();
count = 0;
winText.text = "";
SetCountText ();
}
void Update()
{
if (!gameOver) {
timeLeft -= Time.deltaTime;
}
timerText.text = timeLeft.ToString ("0.00");
if(timeLeft < 0) {
winner = false;
GameOver(winner);
}
}
void GameOver(bool winner)
{
gameOver = true;
timerText.text = "-- --";
string tryAgainString = "Tap the touch pad to try again.";
if (!winner) { // case A
winText.text = "Time's up.\n" + tryAgainString;
}
if (winner) { // case B
winText.text = "Well played!\n" + tryAgainString;
}
// reset on tap
if (Input.GetMouseButtonDown (0)) {
Application.LoadLevel(0);
}
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Mouse X");
float moveVertical = Input.GetAxis ("Mouse Y");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement * speed);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag ( "Pick Up")){
other.gameObject.SetActive (false);
count = count + 1;
SetCountText ();
if (!gameOver) {
timeLeft += 3;
}
}
}
void SetCountText ()
{
if (!gameOver) {
countText.text = "Count: " + count.ToString ();
}
if (count >= 12) {
winner = true;
GameOver(winner);
}
}