ChensHelpers
Chen.Helpers.UnityHelpers.Extensions
Extensions.GetOrAddComponent<T>(GameObject) Method
An extension that allows fetching or adding a component.
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 GameObject gameObject)
where T : Component;
Type parameters
Parameters
gameObject
UnityEngine.GameObject
The GameObject to fetch from or add to
Returns
T
The component specified as T