Score script

Hey, I was looking for a score counter script.
Ive been looking for a few days now and have found no luck.

This is what I have so far.

I would like the score to show up on the screen. I know its something to do with drawing a GUI but I do not know how to incorporate it into the script.

Hello there!

If you simply want to print the current score to the screen you can do it like this:

function OnGUI() {
    GUI.Label(Rect(0, 0, 200, 100), score.ToString());
}

where would i put that script. ? As you can tell im a scripting noob.

Actually i think i almost got it. I put that script onto a GameObject in the scene.
However when i tried to test it i got an error

Now i have no idea what that means. haha.

try

function OnGUI() {
    GUI.Label(Rect(0, 0, 200, 100), (""+score));
}

Put it in the same script as the OnTriggerEnter, so it knows what the variable “score” is.
Also ToString() isn’t actually required - good method to know but not in that example.

actually Myx is correct. ToString() would work. You just need to declare score

private var score : int = 100
function OnGUI() {
    GUI.Label(Rect(0, 0, 200, 100), score.ToString());
}