// HP script on player
var hitPoints = 20;
var damageAmount = 2;
var ouchText : GameObject;
var hpText : TextMesh;
var diesound : AudioClip;
var gameoverText : GameObject;
var replaybutton : GameObject;
function Start() {
Time.timeScale = 1;
if (hpText) {
hpText.text = hitPoints.ToString();
}
}
function OnTriggerEnter(other : Collider) {
Debug.Log("Trigger hit");
if (other.CompareTag("Finish")) {
ApplyDamage(damageAmount);
Destroy(other.gameObject);
}
}
function ApplyDamage(damageAmount : int) {
hitPoints = hitPoints - damageAmount;
if (ouchText) {
ouchText.active = true;
}
if (hpText) {
hpText.text = hitPoints.ToString();
}
if (hitPoints <= 0) {
// Display Game Over and Stop the game.
if (gameoverText) {
gameoverText.active = true;
}
if (replaybutton){
replaybutton.active = true;
Time.timeScale = 0;
}
}
if (diesound){
AudioSource.PlayClipAtPoint(diesound, transform.position);
}
}
First time on play, it works fine until when its game over and the replay button pops out, on the next run the button won’t go away/destroy. I tried using the Destroy(gameObject) but it doesnt work. Any idea how to destroy a GUItexture?