- Home /
hey how do i enable and disable a guitext object? i have
hey how do i enable and disable a guitext object? i have var Guitext : GameObject; //for gui text
Guitext = GameObject.Find("GUI Text"); Guitext.guiText.enabled = false;
then re-abling it i have
Guitext.guiText.enabled = true;
i have disable it no problem, however i could not reenable it need help
Answer by Bampf · Apr 06, 2011 at 06:16 PM
The problem is that GameObject.Find doesn't find objects after they have been disabled.
One solution is, keep an instance variable set to that object, so you don't have to Find it again to enable it.
Another approach is to keep your own list of objects that you might want to find. (This list can contain any objects you want, active or inactive, gui or other.) Then you can search that array instead of calling Find.
See: http://answers.unity3d.com/questions/14178/cannot-toggle-active-on-gameobjects-that-are-inactive
Answer by taoa · Apr 06, 2011 at 08:25 AM
There's no reason why this shouldn't work. The only place where something wrong could happen is that if
Guitext.guiText.enabled = true;
never gets called. Put a
Debug.log("whatever");
Right before or after to see if it gets called, and if not, try to figure out why this is (for instance inside an Update function of an object that is disabled or something)
Answer by Lewenos 1 · Apr 24, 2011 at 06:09 PM
var textObject : GUIText;
function OnMouseOver () { textObject.text = gameObject.name; textObject.GetComponent(GUIText).enabled = true; }
function OnMouseExit () { textObject.text = gameObject.name; textObject.GetComponent(GUIText).enabled = false; }
Answer by jwilliamsen · Feb 26, 2012 at 10:50 PM
I'm no coder - far from it - but I modified another script for toggling the visibility of an object via a key (Tab in this case) and it works perfectly:
#pragma strict
function Update() {
if (Input.GetKeyDown(KeyCode.Tab)) {
// toggle visibility:
guiText.enabled = !guiText.enabled;
}
}
Your answer
Follow this Question
Related Questions
iPhone GUI Text asks for edit on touch 0 Answers
Iphone gui text 2 Answers
UI.Text glitch when building for iOS device 0 Answers
gui text button dont work 1 Answer
Problem with GuiFont - Not appearing 0 Answers