Multiple objects writing to a single variable on another object's script.

Hello,

I have a number of objects on the play screen, each of of which has an “on” and “off” state (dependent on sprite and tag). States are affected by collision from a single ball object. When the state turns to “on” (after colliding with the ball while previously “off”), I want it to increment a global score count by 1. The count can also be decremented by clicking an “on” object, to make it “off.” When the count reaches a certain number, I want it to load the fail screen.

At the moment, I have a global scoring script on the Ball, with all of the other objects accessing the script in their respective Start methods. When collision happens, the involved object accesses the Ball’s “count” variable and increments it by 1. My problem is that each object is writing it’s own individual “count” variable, rather than writing to the global variable on the Ball, and ignoring the fail code completely. My code below:

Code on the Ball (global scorer):

public float count = 0;

void Update () {
		if (count == 8)
			SceneManager.LoadScene("Fail");
	}

Code on each on/off object:

void Start () {
		float count = GameObject.Find ("Ball").GetComponent<globalscorer>().count;
	}

void ChangeSprite () {
	
		if (spriteRenderer.sprite = dark) 
		{
			spriteRenderer.sprite = bright;
			transform.gameObject.tag = "on";
			count = ++count;

	void OnMouseDown () {

		if (spriteRenderer.sprite = bright) {
			spriteRenderer.sprite = dark;
			transform.gameObject.tag = "off";
			count = --count;
			}

I’m sure I’m missing something fundamental so any help would be appreciated. Ideally, I would like all scoring to be tracked in a single variable on one object, with all other object states informing that variable.

Thanks for any help!

Ended up solving this on my own. Making “count” a public static float allows other scripts, including ones on other objects to access and change the count. In the case of the above, the difference would be:

In the GlobalScorer script

public static float count = 0;

*On each object’s on/off script *

++GlobalScorer.count

As long as the variable is a public static, using . in any script will reference that particular one. Hope that helps anyone dealing with a similar issue