ChensHelpers
Chen.Helpers.UnityHelpers.Extensions
Extensions.GetOrAddComponent<T>(Component) Method
An extension that allows fetching or adding a component through the component of the GameObject.
If the GameObject has the component, it will only fetch it and return the component.
If the GameObject does not have the component, it will add one to it and return the component.
public static T GetOrAddComponent<T>(this Component component)
where T : Component;
Type parameters
Parameters
component
UnityEngine.Component
The GameObject of the component to fetch from or add to
Returns
T
The component specified as T