Singleton score keeping and OnGUI updates

I am using the angry ant singleton example to update a score.

When I hit an instantiated object clone (e.g. balloon) I update the score from it's script...

MySingleton.Instance.Score += 5;

...then I destroy (e.g. pop) the object.

I have a GUIText on the hierarchy that displays the score. I have this script attached to it.

void OnGUI() { guiText.text = MySingleton.Instance.Score.ToString(); }

Works fine and displays my score without any nasty component referencing or attaching objects that could break later. Seems to me the cleanest method of keeping track of a score but I was worried that OnGUI() might be constantly updating that score even though the score doesn't change often. Is this using unnecessary processing to do this? Would it be better to somehow reference the guitext and update it only when the balloon pops and the score changes? Problem to me with that is you have to use getcomponent or someway of contacting the guitext script from my cloned objects (balloons) to update it.

Basically, should I update the score via OnGUI or call a method (e.g. UpdateScore) directly from the balloon object? If the latter, what is the best way of referencing the GUIText's script from an instantiated object.

OnGUI does in fact update every frame. You generally wouldn't attach the OnGUI script to a GUIText object, since OnGUI is totally script-based and doesn't depend on that. You can use an empty game object instead, and the script would contain this:

public Rect scoreRect;

void OnGUI {
   GUI.Label(scoreRect, MySingleton.Instance.Score.ToString());
}

A GUIText object is completely different and only updates when the text is changed, so it can be faster, although the actual performance difference isn't likely to be measurable in most cases. You can make a function in a singleton and attach it to the GUIText:

public void UpdateScore (int addToScore) {
    score += addToScore;
    guiText.text = score.ToString();
}

Then you'd call `MySingleton.instance.UpdateScore (100);` if you wanted to add 100 points to the score and have the text updated.