I wish set and remove GUI Label for some period of time in my application. I see that GUI element can be only placed inside OnGUI function , so when I place GUI Label first time , she stay on the screen, only what I can I manage a content of label, but I wish that label appear and disappear for some case.
You’ll need to use a flag to inform your script when you would like to display the label. For example, along the lines of:
var showLabel : boolean = false;
function Update () {
if (somethingThatYouCareAbout) {
showLabel = true;
}
else {
showLabel = false;
}
}
function OnGUI() {
if (showLabel)
GUI.Label...............blah
}
Thanks for help , but I try this solution with flags, the problem is, when the Label appear for the first time, he stay , but what I wish is that he remove for some period of time, for example
function OnGUI() {
if(labelActive){
GUI.Label(Write something);
yield WaitForSecond(2);
// remove the label from the screen
, and that doesn’t work
}
} :roll: :roll: :roll:
Ooo… not sure what the BEST way to do that is, but I usually use a GUI Text object for stuff like that. Create it the way you want it, attach a lifecycle script that basically just does something like:
function Start() {
Destroy(gameObject, 2);
}
and then instantiate it from a prefab when you need it to display:
var guiTextObject : GUIText;
function Whatever() {
var thisGuiTextObject : GUIText = Instantiate(guiTextObject, Vector3(0.0, 0.0, 0.0), transform.rotation);
thisGuiTextObject.text = "Whatever you want it to say this time around";
}
Yes this looks promising , as I figurate out I attach script to some empty GameObject, and then I do all my actions to that Object.
Thanks