Coin collecting + screen on score

Hi guys,

first I wanna say that my english is very bad so I hope you can understand me.
I’ve made a script for coin collecting but now I want that the gamer can see his score.
I search everywhere for scripts but it is al for coin collecting + score,
this is my script:

static var Coin = 0;

function OnControllerColliderHit(hit : ControllerColliderHit)
{
if((hit.collider.gameObject.tag == “coin”))
{
//print(“Coins found”);
//destroy the coin
Destroy(hit.gameObject);

//add Coin to inventory
Coin += 1;
print(“You now have “+ Coin +” coins” );

}
}

what do I need to get the score on screen?
please help :frowning:

1 Like

Basically you need to make a GUIText object in the scene and then your score script on it that tells it to put that GUIText on screen

using function OnGUI…
something like from this thread : http://forum.unity3d.com/threads/184038-First-Person-Scripts-Switching-Weapons?highlight=OnGUI

another link that might help : http://forum.unity3d.com/threads/145704-Coin-script-help?highlight=coin+collect

public GameObject guiTPrefab;//Public var to load a GuiText prefab into on inspector

void start(){
score = Instantiate(guiTPrefab, gameObject.transform.position, Quaternion.identity) as GameObject;
}

void updateScore(){
score .guiText.text = Coin;
}

I know its in c# but it should be easy enough for you to convert that over to java and then just call updateScore after you change coin’s value

or you can just add an OnGUI function to the OP.

 function OnGUI () {
        GUI.Label (Rect (10, 10, 100, 20), Coin + "");
    }

(the '+ “” ’ bit is a way to convert an int to a string without a lot of hassle casting)

Thanks you guys! :smile: