using UnityEngine; public static class GameObjectExtension { public static T GetOrAddComponent(this GameObject gameObject) where T : Component { return gameObject.TryGetComponent(out T t) ? t : gameObject.AddComponent(); } }