- Home /
The question is answered, right answer was accepted
Refering to gameobject script is attached to
What is the best way in C# to refer to the gameobject that the particular script is attached to, IE, is there something similiar to "this"?
Answer by Jessy · Jan 27, 2012 at 04:14 PM
http://unity3d.com/support/documentation/ScriptReference/Component-gameObject.html
"this" is the script instance, not the Game Object to which the script instance is attached.
Yep, looks like the API links are broken again.
You have an API on your local machine. Find the Unity Install Directory :
C:/Program Files/Unity/Editor/Data/Documentation/Documentation/ScriptReference/Component-gameObject.html
Here's the details from that page :
Component.gameObject
var gameObject : GameObject
Description : The game object this component is attached to. A component is always attached to a game object.
C#
using UnityEngine; using System.Collections;
public class example : $$anonymous$$onoBehaviour { void Example() { print(gameObject.name); } }
Follow this Question
Related Questions
Two exact objects behaving differently... *scratches head* 0 Answers
C# GetComponent Issue 2 Answers
C# Check If Gameobject is within Collider 1 Answer
Using Scripts in AssetBundles 0 Answers
Moveing my camera 1 Answer