Component - KurbanismailovZaur/Extensions GitHub Wiki
On this page you can familiarize yourself with the extension methods of the Component class.
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>();Will try to find the component on child objects (including the current one).
var found = transform.TryGetComponentInChildren<Renderer>(out BoxCollider collider);Will try to find the component on parent objects (including the current one).
var found = transform.TryGetComponentInParent<Renderer>(out BoxCollider collider);