Component - KurbanismailovZaur/Extensions GitHub Wiki

On this page you can familiarize yourself with the extension methods of the Component class.

GetOrAddComponent

Returns an already existing component on the current game object, or if there is none, create and get one. Since all scripts inherit from the Component class, you can also use the this keyword.

var collider = transform.GetOrAddComponent<BoxCollider>();

TryGetComponentInChildren

Will try to find the component on child objects (including the current one).

var found = transform.TryGetComponentInChildren<Renderer>(out BoxCollider collider);

TryGetComponentInParent

Will try to find the component on parent objects (including the current one).

var found = transform.TryGetComponentInParent<Renderer>(out BoxCollider collider);
⚠️ **GitHub.com Fallback** ⚠️