the code i’m using dose not quit the game when i press the button what might i be doing wrong
here is the none working code(i have also try’ed just Quit instead of CancelQuitnut that dont work either)
if(GUI.Button(new Rect(1020,40,110,25), "Quit Game")) {
Application.CancelQuit();
my script
///
/// PlayerHealth.cs
/// Display the players health in game
///
/// Attach this class to your player character
///
using UnityEngine;
using System.Collections;
public class PlayerHealth : MonoBehaviour {
private const string DEFAULT_DROP_ZONE_NAME = "dz_Default2";
public GameObject destination;
public int maxHealth = 100;
public int curHealth = 100;
public float attackTimer;
public float coolDown;
public float healthBarLength;
// Use this for initialization
void Start () {
attackTimer = 0;
coolDown = 4f;
healthBarLength = Screen.width / 2;
}
// Update is called once per frame
void Update () {
AddjustCurrentHealth(0);
if(attackTimer > 0)
attackTimer -= Time.deltaTime;
if(attackTimer < 0)
attackTimer = 0;
if(Input.GetKeyDown(KeyCode.H))
if(attackTimer == 0) {
AddjustCurrentHealth(10);
attackTimer = coolDown;
}
}
void OnGUI() {
GUI.Box(new Rect(10, 10, healthBarLength, 20), curHealth + "/" + maxHealth);
GUI.Box (new Rect (580,10,65,25),"Heal (H)");
if(GUI.Button(new Rect(1020,10,110,25), "Reset Game")) {
Application.LoadLevel(0);
}
if(GUI.Button(new Rect(1020,40,110,25), "Quit Game")) {
Application.CancelQuit();
}
}
public void AddjustCurrentHealth(int adj) {
curHealth += adj;
if(curHealth < 0)
curHealth = 0;
if(curHealth > maxHealth)
curHealth = maxHealth;
if(maxHealth < 1)
maxHealth = 1;
if(curHealth <= 0)
{
if( destination == null )
destination = GameObject.Find( DEFAULT_DROP_ZONE_NAME );
transform.position = destination.transform.position;
}
healthBarLength = (Screen.width / 2) * (curHealth / (float)maxHealth);
}
}
i try'ed that once did not work but it works now thanks
– Djspun