- Home /
How to set a counter to increase as an object increases on the X axis
Hey, I am trying to develop a GUIText when the object (Player) increases on the x axis. For every 6 units I want 1 extra point be displayed on the GUIText. This is the code I am using:
#pragma strict
var score : float = distance / 6;
function Start () {
}
function Update ()
{
if(gameObject.tag == "Player" + (6, 0, 0)
{
GUI.Label(Rect((Screen.width / 2) + 20,10, 200, 30), "Score: " + score);
}
What am I doing wrong? Thanks in advanced.
Answer by robertbu · Mar 02, 2014 at 06:31 PM
GUI functions can only be executed inside the OnGUI() callback. So to display your text you you would do:
function OnGUI() {
GUI.Label(Rect((Screen.width / 2) + 20,10, 200, 30), "Score: " + score);
}
Unless you are dynamically changing your tags, I'm not sure about your if() logic. If it is good, you can put it in the OnGUI() as well, but I'd start by just getting the text to display.
Your answer
Follow this Question
Related Questions
variable++ error... 1 Answer
guitext count up when collide 1 Answer
Run time counter 1 Answer
Only tagged objects raise counter 1 Answer
Making something happen only for one second during an Update function? 1 Answer