- Home /
Change The GuiText.text by code
Hello EveryOne! I have a small issue here: I want to display the tag for my prefab as a title which is a GuiText. I have the script named "InstantiatePrefab", and the portion for this issue is here:
var modelTitle:GUIText; //dragged reference
function CreateNext()
{
Destroy(prefab);
count++;
prefab = Instantiate (myArray[count], gameObject.transform.position , Quaternion.identity);
prefab.transform.parent = transform;
modelTitle.text = prefab.tag;
}
I want simply to display the user of what is the model he see's (ex: Eiffel Tower), I am sure I have set the tag for my models.
If you can see your GUItext object on the screen, and have attached that to the modelTitle variable in the inspector, tags are registered and attached to your prefabs, you get not any errors on the script execution, it would be difficult to see any reason for your titles to not display.
I had to do modelTitle.guiTexture.text = prefab.tag; ins$$anonymous$$d of modelTitle.text = prefab.tag;
That doesn't make any sense, as a GUITexture doesn't have a "text" property, but as long as it worked out for you...
Could you clarify, moghes, as far as I know, text is not the property of guiTexture.
yes its not a property of guitexture and that's why it didn't work the first time, u are right
Answer by Tim-Michels · Jun 19, 2012 at 10:40 AM
I would use a TextMesh. Simply add a 3D Text object to the scene, which has a TextMesh component. The text can by changed by setting TextMesh.text = "test";
If you're having problems with the sharpness of the text, change the import settings of the font. The size property in the import settings is default pretty low, so make this size higher, and downscale the Textmesh gameobject accordingly.
Cheers