How do you show/hide textUI in Javascript?

I have searched for an hour looking for somebody who explains how to do this in Javascript. I need to show and hide my text objects by the press of a button and here is my current code. I need something similar to .enabled or .setactive but I get errors from both of them.

.setactive only seems to work for objects because I get the error that setactive and enabled are not apart of UI.Text.

My varibles are defined as

var woodText : UI.Text;

My key pressing code

	if(showGUI == true)
	{
		inventoryPanel.SetActive(true);
		Time.timeScale = 0;
	}
	
	if(showGUI == false)
	{
		inventoryPanel.SetActive(false);
		Time.timeScale = 1;
	}
}

1 Answer

1

UI.Text has the enabled property, inherited from Behaviour: http://docs.unity3d.com/ScriptReference/UI.Text.html

If you can’t use that you have some other problem in your script.

If you want to use SetActive instead (which disables a whole GameObject instead of just a component) you need the gameObject first:

woodText.gameObject.SetActive(true); //or false

Thank you so much, I could not find that in the documentation or anywhere!