- Home /
Can't destroy an arrray with GUI Text
I Instantiated a GUI Text Game object and put them in a array, but when i use Destroy(); nothing happens, i can see the objects in the scene hierarchy.
Try Destroy(gameObject);
I don't believe there's a parameteless overload for the Destroy method.
I did't want to copy the hole text but i tried
Destroy(planetLabels[i]);
and
Destroy(planetLabels[i].GetComponent(GameObject));
because the component of the object is GUIElement
You wouldnt call its gameobject component like that, try this
Destroy(planetLabels[i].gameObject);
You may need to edit the length of your array to remove the empty slot. If you are using Array() you can use remove at
planetLabels.RemoveAt(i);
which will be called after you call destroy, if you remove the slot first you wont have the path to that gui text
I Instantiated a GameObject not a GUIText, and then Destroy
worked as hoped. Also a can get/set the information for the GUIText from the object I just used for example NameOfGUIText.guiText.text = "some text"
If you did want to reference the GUIText itself you can use the method i provided( adding .gameObject to the array ref). Sounds like you found your answer?
Answer by simeonradivoev · May 09, 2012 at 11:00 PM
I Instantiated a GameObject not a GUIText, and then Destroy worked as hoped. Also a can get/set the information for the GUIText from the object I just used for example
NameOfGUIText.guiText.text = "some text"
but it seems that you can also call the gameobject of the GUIText like this
Destroy(planetLabels[i].gameObject);
not sure if it works with instantiated objects.