Component
Base class for everything attached to a GameObject.
Read time 4 minutesLast updated 3 days ago
Definition
- Type: Class
- Namespace: UnityEngine
- Assembly: UnityEngine.CoreModule
- Inherits from: Object
public class Component : Object
Remarks
Note that your code will never directly create a Component. Instead, you write script code, and attach the script to a GameObject. Additional Resources: ScriptableObject as a way to create scripts that do not attach to any GameObject.
Properties
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. |
Methods
Method | Description |
|---|---|
| BroadcastMessage | Calls the method named methodName on every MonoBehaviour in this game object or any of its children. |
| CompareTag | Checks the GameObject's tag against the defined tag. |
| 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 methodName on every MonoBehaviour in this game object. |
| SendMessageUpwards | Calls the method named methodName on every MonoBehaviour in this game object and on every ancestor of the behaviour. |
| 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. |