GUIText enable/disable

Sorry if this has been answered elsewhere, I searched but couldn’t find the answer.
I have a simple GUIText, made by the Game Object > Create Other > GUIText menu.
I’ve created an animation for it, which works.
Now, I want to hide it, until the player hits a trigger. That’s all! I’m sure it’s something.enabled = true/false in js, but everything I try gives me various errors.
Any help would be gratefully received, (and sorry for the noob question)
Thanks
Ian

2 Answers

2

Try to use this code :

//to enable
var guiComponent = GetComponent("GUIText").guiText;
guiComponent.enabled = true;

Let me know if this helped you :slight_smile:

Thanks for your reply Anton. I tried your code, but it keeps asking for a semicolon after the first line :-/ I'm trying to get it working, and it's closer than any of my efforts! Thanks again Ian

Use this : <p>var guiComponent = GetComponent("GUIText").guiText; guiComponent.enabled = false;

OK, I realise what was wrong... I'm working in JavaScript, and this is C# :) Thanks a lot for your help, really appreciated. I'll try and convert this to JS eventually so I can do more with it ;)

guiComponent.enabled = true; doesn’t seem to work in my case but

guiComponent.active = true;

does. I have no idea why but can’t hurt to have an option.