I have 2 GUI labels in the top left corner, one shows the amount of gems you’ve collected and the other shows the amount of coins you have, the problem that I’m having is that once you start the game they will both show 0 (Which is fine). However as soon as you collect one of the gems the coins number will update from 0 however the gems collected number will just completely disappear. I will show this with an image below. Can anyone explain why this happens?
Here is the code also. The amount of score rewarded for redGem and blueGem is set in the inspector and they’re not 0.
#pragma strict
var score = 0;
var redGem = 0;
var blueGem = 0;
var coins = 0;
function Start () {
}
function Update () {
}
function OnTriggerEnter (other : Collider) {
if(other.gameObject.tag == "redGem"){
score += redGem;
coins += 100;
Destroy(other.gameObject);
}
else if(other.gameObject.tag == "blueGem"){
score += blueGem;
Destroy(other.gameObject);
}
}
function OnGUI(){
GUI.Label (Rect (10, 10, 100, 20), "Gems Gained: " + score);
GUI.Label (Rect (10, 30, 100, 20), "Coins: " + coins);
}
redGem and blueGem are values set in the inspector the 0 that you see are just the default values in coding. You were right with the rect being too small for the gems gained. How did I not think of trying that haha, feel like such an idiot now.
Thanks for that man, sometimes it just takes a second person to notice something
Oops. I should have realized about the gems. I don’t use UnityScript very often, and didn’t see “public,” so it didn’t occur to me. Also, glad I could help.