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.