Я пытаюсь расширить это руководство по Roll-a-Ball, включив в него таймер и позволить пользователю повторить попытку, коснувшись сенсорной панели, независимо от того, выиграют они или закончатся время.
Это работает, как и ожидалось, если время истекло (// 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);
}
}