player == null not working

I have a script for the player so when the player object is destroyed, a gui text appears but it wont work. When the player dies nothing happens.

CODE

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class Player : MonoBehaviour
{
	
	public Text countText;
	private int count;
	public Text endText;
	
	
	void Start ()
	{
		count = 0;
		SetCountText ();
		endText.text = "";
		
	}
	
	
	
	void OnTriggerEnter2D(Collider2D col) 
	{
		if(col.gameObject.tag == "Coin")
		{
			col.gameObject.SetActive (false);
			count = count + 1;
			SetCountText ();
		} else if (col.gameObject.tag == "Enemy")
		{
			Destroy(gameObject);
		}
	}
	
	void SetCountText ()
	{
		countText.text = " " + count.ToString ();

		if (gameObject == null) {
			endText.text = " " + count.ToString ();
		
		}

		
	}
}

If you destroy your gameObject you will lose your gameObject… to be clear the gameObject AND the attached component will be deleted (your script are part of it). So When you do that :

Destroy(gameObject);

the function :

 void SetCountText ()

will never be called again …
You can edit your text before destroying your gameObject.

endText.text = " " + count.ToString ();
Destroy(gameObject);

Hope this help…

Veldars is absolutely right. As an additional advice, I suggest to avoid a control like that (with the “== null”) but to add the logic of the GUIText rendering inside the OnDestroy() function. This one is called as soon as the object exihibiting it is destroied.

void OnDestroy(){
   //Render the GUIText
}