Why won't my score counter count normally? sometimes it counts and other times it does nothing. Can someone help?

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


public class balldestroy : MonoBehaviour {

	static int count;
	public Text countText;
	// Use this for initialization
	void Start () {
		count = 0;
		SetCountText ();
		Destroy (this.gameObject, 10);
	}
	
	// Update is called once per frame
	void Update () {
		
	}

	void OnMouseDown() {
		if(Input.GetMouseButton (0))
		{
			count += 1;
			SetCountText ();
			Destroy (this.gameObject);
		}
	}

	void SetCountText(){
		if(countText != null){
		countText.text = "" + count.ToString ();	
		}
	}


}
[\CODE]

When you call Destroy (this.gameObject), your script won’t run anymore because the object it’s attached to has been destroyed.

Try removing both Destroy (this.gameObject, 10); and Destroy (this.gameObject);. If it works, you’ll have to find another way to keep score or remove the ball so your script can keep counting the score.

If the problem persists, you’ll know that the cause is somewhere else, and we’ll have to look deeper.