x


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;}
   ;}
more ▼

asked Nov 19 '10 at 01:05 AM

Tyler 2 gravatar image

Tyler 2
1.1k 211 246 264

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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;
    }
    }
more ▼

answered Nov 19 '10 at 02:22 AM

SirVictory gravatar image

SirVictory
1.7k 66 77 104

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5098
x3698
x123

asked: Nov 19 '10 at 01:05 AM

Seen: 667 times

Last Updated: Nov 19 '10 at 01:05 AM