Instantiate Text then delete it

So I instantiate a text prefab like so:

theText = (Text)Instantiate(GuiText);

Destroy(theText);

But when i destroy it, the game object is not destroyed, only it’s Text Component.

What’s wrong?

Fixed it by instantiating a GameObject and then taking it’s Text component to work on it (like assigning it’s parent to Canvas).

guiTextObj = (GameObject)Instantiate(GuiText);
textComponent = guiTextObj.GetComponent<Text>();

Try destroy theText.gameObject? Or don’t cast?

2 Likes

Oh your method is better!

Thanks :smile: