Quantcast
Channel: Answers for "How come I don't have to type "GetComponent(transform)()" but instead I can just type "gameObject.transform"?"
Viewing all articles
Browse latest Browse all 4

Answer by Benproductions1

$
0
0
The Component class has getters for most of the built-in components. Quite literally: public class Component : Object { public Transform transform { get { return GetComponent(); } } // etc } Note, that `MonoBehaviour` is a class inside of the `UnityEngine`. `MonoBehaviour` inherits from `Components`. So to answer your question, it's both because of `MonoBehaviour`, `UnityEngine` *as well as* `Component`. Also note, that `GetComponent` is actually an alias for `gameObject.GetComponent`. A bunch of functions are like this and exist purely to make things a little bit easier.

Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images