Need help with GUI script. (C#)

Hi Guys,

I seem to have a problem with my script. My script will go onto the player and what i want it to do is when they player is destroyed the guitexture will show. I have script but it wont work.

Any help would be great

Script

using UnityEngine;
using System.Collections;

public class ShowGameOver : MonoBehaviour {

	public GUITexture GameOver; 

	void OnDestroy() {
		GameOver.SetActive(true);
	}
}

GUI elements are drawn in the OnGUI() method. Have you attached it to a game object? If you have, it should work.

Is this script on your player?

I’ve had problems with using OnDestroy and typically call what I want to happen before Destroy gets called instead.

For example:

 public GUITexture GameOver;

 void TakeDamage(int amount){
     health -= amount; //however you are lowering health
     if(health <= 0){
          GameOver.SetActive(true);
          Destroy(this.gameObject);
     }
 }

Also you probably didn’t do this, but make sure your GUITexture is not a child of an object being destroyed.