score system failure

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

public class score : MonoBehaviour {

    public int ballValue;
    public Text scoretext;
	// Use this for initialization
	void Start () {
        ballValue = 0;
	
	}
	
	// Update is called once per frame
	void Update () {
        scoretext.text = ballValue.ToString();
	
	}

    void OnTriggerEnter2D(Collider2D other)
    {
        if(other.gameObject.tag == "bucket")
        {
            ballValue = ballValue + 1;
        }
    }

}

ok guys what am i doing wrong over here ,i am a beginner.what i am trying to achieve here is i want my ball to fall down to the bucket and get 1 point or score ,my ball has a actual circle collider and a rigidbody and my bucket has box collider which is a trigger and both of these are prefabs which is being used multiple times in the games just in case if anyone want to know.so can anyone tell me what i a, doing wrong or can someone guide to the right tutorial .thank you

Are you only using 2D colliders or are you mixing 2D and 3D colliders?

Also the null ref could be caused by you not linking scoretext to a TextField in the inspector.

You need the canvas (or something that isn’t instantiated and destroyed) to hold a script that keeps the score, that score int needs to be public. Tag that thing so it’s easy to find, lets sat it’s the Canvas so tag it with an appropriate name like MainCanvas.

Then in the script attached to the buckets you instantiate.

private GameObject mainCanvas;
private ScoreScript myScoreScript;


void Start()
{
    mainCanvas = GameObject.FindWithTag("MainCanvas");
    myScoreScript = mainCanvas.GetComponent<ScoreScript>();
}

Now when it detects the collision/trigger you can update the score variable in the ScoreScript.

myScoreScript.score ++;

and get the score script to update the text.

this way all buckets can find the right script and update the score.

I’ve typed this without access to unity so there may be a few errors but the theory is sound.