x


coin collecting with onscreen score

var score = 0;
function OnTriggerEnter( other : Collider ) {    
   if (other.tag == "Coin") {        
      score += 5;        
      Destroy(other.gameObject);
   }
}

i use this code to collect coins, but cannot get it do display onscreen, i'm not a programmer, just a designer, so can advice a simple help? :)

more ▼

asked Jul 12 '10 at 02:47 PM

Nick 1 gravatar image

Nick 1
18 2 3 5

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

2 answers: sort voted first
function OnGUI()
{
    GUILayout.Label( "Score = " + score );
}

Put that in your script.

more ▼

answered Jul 12 '10 at 03:12 PM

Tetrad gravatar image

Tetrad
7.2k 27 37 89

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

i'll try it now, does this script keeps the score for a next level, or i have to search forward? :)

PS it works :) and by the way how can i change the font since it's not a GUI text object

more ▼

answered Jul 12 '10 at 05:02 PM

Nick 1 gravatar image

Nick 1
18 2 3 5

(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:

x3694
x555
x274
x16

asked: Jul 12 '10 at 02:47 PM

Seen: 2720 times

Last Updated: Jul 12 '10 at 03:10 PM