using UnityEngine; public static class GameObjectExtension { public static T GetOrAddComponent(this GameObject g) where T : Component { T ret = g.GetComponent(); if (ret == null) { ret = g.AddComponent(); } return ret; } }