- Home /
How to call the gameobject instance where the script is attached?
.this and .gameObject are not working in my script.
Answer by dannyskim · Mar 28, 2012 at 06:15 PM
Do you have an instance of the gameObject declared as a variable? Need more information, the 'this' keyword inside of Unity refers to the object that you're scripting in, which would directly correlate to the script itself, not the gameObject.
If you have no variable declared and are trying to access it directly, there is no reason why you should be using the '.' in front of the 'gameObject', it should just be gameObject.
Answer by sebas77 · Mar 28, 2012 at 06:14 PM
if you are inside a monobehaviour, this.gameObject should work
Answer by MetalLord · Mar 28, 2012 at 06:43 PM
I changed to this.gameObject.transform.position and it worked,thanks guys.
Your answer
Follow this Question
Related Questions
Restricting "Drag GameObject" script to Z Axis? 1 Answer
Using Scripts in AssetBundles 0 Answers
Moveing my camera 1 Answer