- Home /
find GUIText
hey, I`m trying to make a prefab instantiate and then find a GUIText though i have no idea how so here is what i got:
var PlayerHealthDisplay: GUIText;
function DisplayAmount () {
if (GUIText){
PlayerHealthDisplay.text = "" + health;
}
}
function Start () {
PlayerHealthDisplay = guiText.tag == "Health";
}
the console says that it cant convert a Boolean into a UnityEngine.GUIText
Answer by Berenger · Jun 21, 2012 at 11:17 PM
GUIText is a type, so you can't test if it's null (the if). PlayerHealthDisplay is an object of type GUIText, and you're trying to assign it a boolean, that's not possible.
To change the text, you need to do this :
if( PlayerHealthDisplay != null )
PlayerHealthDisplay.text = "Your text here";
so knowing that, is there a way to find a GUIText, or assign it at the beginning?
IF you can do it in the editor, you can use the FindObjectOfType or FindWithTag functions.
Find, FindGameObjectsWithTag or FindObjectsOfType, or maybe a combination, depending on your search criteria.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
finding instantiated prefabs 2 Answers
How do I acces a specific GameObject within the terrain???? 1 Answer
Instantiate with Prefabs 2 Answers
Network.Destroy and collision; destroying correct object. 1 Answer