- Home /
GUI Label script problem???
hey guys, i have got this script here, and what it does is: when i apply it to the player, and then drag a game object into the "objective" variable, it is meant to display the GUI Label for 5 seconds on the screen. It all works fine if i don't use the whole "timing" method, but just make it display for ever. But as soon as i add the parts to make it so that it will only display for 5 seconds it won't show up on screen.
private var ShowLabel : boolean = true;
var objective : Transform;
var style : GUIStyle;
function Start()
{
yield WaitForSeconds(5);
ShowLabel = false;
}
function OnGUI()
{
if (Vector3.Distance(transform.position, objective.position) < 3000){
if(ShowLabel)
{
GUI.Label(Rect(650, 650, 300, 50), "MY GUI TEXT", style);
}
}
}
There are no errors in the console, and as i said, it will work fine with the vector3.distance funtion with a normal GUI.Label, but with the timing it doesn't appear.
can someone please tell me what i have done wrong....
any answers are greatly appreciated...
thanks
-Grady
Answer by Molix · Jul 01, 2011 at 01:25 AM
Your script looks fine, as long as objective is set in the inspector. My guess is that 650, 650 is off screen. Put it at 0,0 and give it a whirl.
i was just mucking around with it, and on line 16, the if statement, if i change the distance value from "< 3000" to "< 5000" it works, but nothing less then 5000 seems to work, and it sure work with any number, so i'm a bit confused...
Sounds like your objective is very far away from the object with this script (i.e. somewhere between 3000..5000 units).
yeah, it's an aircraft game, so the player's object is an aircraft... :/
Your answer
![](https://koobas.hobune.stream/wayback/20220612130533im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
how to script a timed GUI Label into my script 1 Answer
GUI.label overlapping text 1 Answer
GUI in the middle of the screen 1 Answer
How to make 3D Text fade in and out? 3 Answers