x


Can't add component GUITexture

Hi,

I'm trying to create GUITextures on the fly but I keep on getting this error ->

"Can't add component 'GUITexture' to something different because such a component is already added to the game obejct!"

Here is an example of test code what I'm trying to accomplish

GUITexture textureTest1 = gameObject.AddComponent<GUITexture>() as GUITexture;

GUITexture textureTest2 = gameObject.AddComponent<GUITexture>() as GUITexture;

the error appears when gameObject adds a component the second time.

I don't really understand because you can attach many GUITextures components through the editor?

I would really appreciate if some one could possibly explain to me why this does not work.

Kind Regards

more ▼

asked Dec 03 '10 at 05:28 PM

lee gravatar image

lee
11 1 1 2

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You can't add multiple GUITextures to a single GameObject in the editor either

If you're doing GameObject > Create Other > GUI Text, it's creating a new GameObject each time

What you could do is something like this:

GameObject go1 = new GameObject("1"); 
GUITexture textureTest1 = go1.AddComponent<GUITexture>();

GameObject go2 = new GameObject("2");
GUITexture textureTest2 = go2.AddComponent<GUITexture>();
more ▼

answered Dec 03 '10 at 05:32 PM

Mike 3 gravatar image

Mike 3
30.5k 10 65 253

Ahh i see, because through the editor, when you create a GUITetxure the are already assigned to a game object. Duh, that makes sense. thanks for the answer Mike :)

Dec 05 '10 at 12:19 PM user-7110 (google)
(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:

x2097
x478
x77

asked: Dec 03 '10 at 05:28 PM

Seen: 1943 times

Last Updated: Dec 03 '10 at 05:28 PM