x


How can I get my own gameobject?

Hi, I'm a script in JS and I want to get the reference to my own gameobject so that i can do this: abc = gameObject.AddComponent("AbcScript");

Is it possible?

Thanks!

more ▼

asked Aug 19 '12 at 07:38 PM

NeMewSys gravatar image

NeMewSys
123 6 16 23

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

2 answers: sort voted first

If the script you are using is on the object you want to destroy, you can use Destroy(gameObject); It will destroy itself.

more ▼

answered Aug 19 '12 at 07:49 PM

GlitchBait gravatar image

GlitchBait
123 1 3 10

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

That's correct: gameObject alone is a reference to the object to which the script is attached, thus you will add AbcScript to it and get a reference to the script in abc. The same applies to transform, renderer, collider etc.

more ▼

answered Aug 19 '12 at 07:47 PM

aldonaletto gravatar image

aldonaletto
41.5k 16 42 197

Ah so that's the difference between gameObject and GameObject! I always think that gameObject was a typo for GameObject class lol.

Thanks guys, 2 questions in 1! ;)

Aug 19 '12 at 07:59 PM NeMewSys
(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:

x2091
x424
x77
x12
x8

asked: Aug 19 '12 at 07:38 PM

Seen: 363 times

Last Updated: Aug 19 '12 at 07:59 PM