Because score is static, you only need to reference the name of the script in order to use it. I believe that GUItext is created every frame or so, (Correct me if I’m wrong) and it will update accordingly.
EDIT: JM Studios, wouldn’t that be illogical? Why would the collider want to know the overall score?
I don’t see any reason it wouldn’t work. I strongly suggest not to put the score in with a collider, as that is, in my opinion, very illogical and will only lead to hard to manage code.
Here’s my attempt at writing the script:
static var score : int = 0;
function OnGUI () {
GUI.Label( Rect(Screen.width - 20, Screen.height - 20, 100, 20), "Counter is: " + (score));
}
And when you have a collision, NameOfScript.score++;
The script is not attached to a GUI element, as all of Unity GUI is created each frame, through script. Again, I strongly suggest you look back into this, but if you still cannot get it working, JM Studio’s method is “acceptable” in my opinion.
what do you mean [quote=“DanielQuick, post:7, topic: 432391, username:DanielQuick”]
JM Studio’s method is “acceptable”.
[/quote]
it looks like you just copied my script and deleted the
Yes, I did pull most of the code out of yours, but I changed an important piece. The fact that it is not attached to a collider. I could have simply explained my point by referencing your code, but I decided to separate it in order to separate our ideas. I’m sure your way would work in many situations, but, in my opinion, it is very bad form to have the score attached to a collider.
To summarize: Your code was correct, however, I believe that there is a better way of implementing it.