I am working on a personal project and have almost everything done expect for one last bit of stubborn code. What I have is a trigger which is behind the player and every time a rigid body hits that trigger the count goes down by one. When the count hits a certain negative number then the game is over and the player is given the chance to restart the game. I got most of it worked out but I am getting a error that is causing the game to say game over when it is only at -1 and not at -10 which is where I want it to say "Try Again!" Can you please tell me where my error is? Overall the code is working pretty good. `using UnityEngine;
using System.Collections;
public class Escaped : MonoBehaviour
{
private int count;
public GUIText countText;
public GUIText tryagainText;
public GUIText restartText;
public GUIText gameOverText;
private bool restart;
// Use this for initialization
void Start ()
{
restart = false;
restartText.text = "";
gameOverText.text = "";
tryagainText.text = "";
}
// Update is called once per frame
void Update ()
{
if (restart)
{
if (Input.GetKeyDown (KeyCode.R))
{
Application.LoadLevel (Application.loadedLevel);
}
}
}
void OnTriggerEnter(Collider other)
{
count =count -1;
countText.text = "count : " + count.ToString();
if(count >= -10)
{
tryagainText.text = "Try Again!";
gameOverText.text = "Game Over!";
restartText.text = "Press 'R' for Restart";
restart = true;
}
}
}`
↧