Component
Base class for everything that can be attached to a GameObject.
Read time 4 minutesLast updated 5 days ago
Definition
- Type: Class
- Namespace: UnityEngine
- Assembly: UnityEngine.CoreModule
- Inherits from: Object
public class Component : Object
Remarks
Note that you don't instantiate the class directly. Instead, you write code in MonoBehaviour scripts, which inherit from , and attach the scripts to a GameObject. Additional Resources: ScriptableObject as a way to create scripts that do not attach to any GameObject.
ComponentComponentProperties
Property | Description |
|---|---|
| gameObject | The game object this component is attached to. A component is always attached to a game object. |
| tag | The tag of this game object. |
| transform | The Transform attached to this GameObject. |
| transformHandle | The TransformHandle of this GameObject. |
Methods
Method | Description |
|---|---|
| BroadcastMessage | Calls the method named |
| CompareTag | Checks the GameObject's tag against the defined |
| GetComponent | The string-based version of this method. |
| GetComponentInChildren | This is the non-generic version of this method. |
| GetComponentIndex | Gets the index of the component on its parent GameObject. |
| GetComponentInParent | The non-generic version of this method. |
| GetComponents | The non-generic version of this method. |
| GetComponentsInChildren | The non-generic version of this method. |
| GetComponentsInParent | The non-generic version of this method. |
| SendMessage | Calls the method named |
| SendMessageUpwards | Calls the method named |
| TryGetComponent | The non-generic version of this method. |
Inheritance
Operators
Operator | Description |
|---|---|
| operator == | Compares two object references to see if they refer to the same object. |
| bool | Determines whether the object exists. |
| operator != | Compares if two objects refer to a different object. |