- Home /
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!
Answer by GlitchBait · Aug 19, 2012 at 07:49 PM
If the script you are using is on the object you want to destroy, you can use Destroy(gameObject); It will destroy itself.
Answer by aldonaletto · Aug 19, 2012 at 07:47 PM
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.
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! ;)
Your answer
Follow this Question
Related Questions
Is it possible to determine if OnDisable() is being called from parent.SetActive( false ) or self? 2 Answers
change pivot of parent game object 1 Answer
Building asset bundles and wanting to move game objects from one parent to a newly created parent 1 Answer