Updating GUI.Label for Score

I am trying to use a GUI.Label to update the score of my game. My problem is I do not know how to get the score to increase on the GUI. I know that label is just used to display information, and I have tried using a string instead, but it didn’t work for me. I might have done it wrong so I am asking for help. Here is my script for the text

public var score : int = 0;

function OnGUI ()
{
GUI.Label (Rect (25, 25, 100, 30), “Score:” + score);
}

function OnCollisionEnter(collision : Collision)
{
//if I collide with a bullet,destroy myself

if(collision.gameObject.tag=="Bullet")
    {	
	score += 1;
	Destroy(gameObject);
    }
}

EDIT: The GUI shows up and shows a starting score of 0 when I destroy the object in question, the score does not change in the GUI but if I Debog.Log, the score goes up by 1.

My Label does update the score “in the console it says so” but it dosent show up in the game. Help?

hmm from what I seen your code should work I have an example I did too test my health in game it’s in c# through but should be easy too change.
void Update ()
{
if(Input.GetKeyDown(GUIKey))
{
Life -=1;
}
}
it update’s correct when is pressed my GUI label is in another script but works for what you want.

I was having the same problem. Don’t make the variable “score” a public variable, make it static.
So instead of:

public var score : int = 0;

Use:

static var score : int = 0;

Instead of:

function OnGUI () { 
GUI.Label (Rect (25, 25, 100, 30), "Score:" + score); 
}

Try:

function OnGUI () { 
GUI.Label (Rect (25, 25, 100, 30), "Score:" + score.ToString()); 
}

Converting the score int to a string value so it can be displayed in the GUI.Label.

Hope that helps, Klep

#pragma strict
var score : int = 0;
function OnGUI () { GUI.Label (Rect (25, 25, 100, 30), “Score:” + score); }

I copy your function and running.Your function have not problem!!!