- Home /
What's the difference between gameObject and transform when using GetComponent
It seems the following all seem to work the same. Is there any difference with what I'm doing here (any performance difference, for example?)
OnTriggerEnter ( other : Collider )
{
other.GetComponent(someScript).Activate();
other.gameObject.GetComponent(someScript).Activate();
other.transform.GetComponent(someScript).Activate();
}
Answer by Berenger · May 08, 2012 at 04:27 AM
A gameObject is a collection of components, whereas transform IS a component. Now, as the property transform is a the same as GetComponent(..) and is accessible from any component, even itself, this is correct (but redondant) :
print( obj.transform.transform.transform.transform.transform.transform.position );
Answer by eaglemaster7 · May 08, 2012 at 04:20 AM
"GetComponent" function is belong to GameObject. but in Transform, it just a Inherited function from GameObject. there's no difference :) CMIIW
Component.GetComponent and GameObject.GetComponent are technically different functions (since neither of those classes inherits from the other), but they do the exact same thing.
Your answer
Follow this Question
Related Questions
Instantiate rigidbody, transform or gameobject? 1 Answer
I want to move a cube with rotation but I find this problem 1 Answer
Is there any way to convert Collision to a Gameobject or Transform? 1 Answer
Difference between Vector3, Transform and GameObject 2 Answers
How to move a gameObject without affecting its childrens' positions? 2 Answers