x


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.

more ▼

asked May 09 '12 at 04:20 PM

simeonradivoev gravatar image

simeonradivoev
37 6 8 9

Try Destroy(gameObject);

I don't believe there's a parameteless overload for the Destroy method.

May 09 '12 at 04:31 PM asafsitner

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

May 09 '12 at 04:44 PM simeonradivoev

@simeonradivoev

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

May 09 '12 at 07:16 PM hijinxbassist

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"

May 09 '12 at 07:41 PM simeonradivoev

@simeonradivoev

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?

May 09 '12 at 10:21 PM hijinxbassist
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered May 09 '12 at 11:00 PM

simeonradivoev gravatar image

simeonradivoev
37 6 8 9

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3698
x2097
x1363
x764
x555

asked: May 09 '12 at 04:20 PM

Seen: 584 times

Last Updated: May 09 '12 at 11:00 PM