- Home /
GUI.box (Score counter) doesn't appear when game is on play.
Hey guys!
I have a problem. I am working on my last part of coding in Unity for a GUI score counter. Via a tutorial I came up with these codes:
(Script name: SugarBehavior = attached to the objects sugarhearts)
using UnityEngine; using System.Collections;
public class SugarBehavior : MonoBehaviour {
void OnTriggerEnter(Collider collider)
{
switch(collider.gameObject.name)
{
case "Player":
SugarController.sugarCount++;
Destroy (this.gameObject);
break;
}
}
}
(Script name: Sugarcontroller = attached to "empty object" SugarController)
using UnityEngine; using System.Collections;
public class SugarController : MonoBehaviour {
public static int sugarCount = 0;
void onGUI ()
{
//string sugarText = "Score: " + sugarCount;
GUI.Box (new Rect(Screen.width - 150, 20, 130, 20), "Score: " + sugarCount);
//GUI.Label (new Rect(Screen.width / 2 - 40, 300, 80, 30), "Score: " + sugerCount);
}
}
Now the problem is that the "GUI.Box"/score doesn't appear when played. The objects are disappearing when touched though... I can't find what is wrong and I have no warnings or errors.
Comment