- Home /
what is wrong with my GUI script?
Hello, I am trying to display the score for my game on the GUI, but when I use my script the score will not show up, what is wrong with my script?
static var Score = 0;
function OnGUI() { GUI.Label(Rect(100,100, 100, 50), Score); }
function OnTriggerEnter (other : Collider) { if (other.gameObject.CompareTag ("Wall")) { Destroy (gameObject);}; if (other.gameObject.CompareTag ("Enemy")) { Destroy (gameObject); Destroy (other.gameObject); Score += 100;} ;}
Comment
Best Answer
Answer by SrBilyon · Nov 19, 2010 at 02:22 AM
Add .ToString to Score so that Score is converted into a string, allowing it to be written to the label.
static var Score = 0;
function OnGUI()
{
GUI.Label (Rect (10, 10, 100, 20), Score.ToString());
}
function OnTriggerEnter (other : Collider)
{
if (other.gameObject.CompareTag ("Wall"))
{
Destroy (gameObject);
}
if (other.gameObject.CompareTag ("Enemy"))
{
Destroy (gameObject);
Destroy (other.gameObject);
Score += 100;
}
}
Your answer
