using UnityEngine; public static class Extensions { public static ComponentA GetOrAddComponent(this GameObject gameObject) where ComponentA : Component { ComponentA result = gameObject.GetComponent(); return result == null ? gameObject.AddComponent() : result; } public static Vector2 Position2d(this Transform t) { Vector3 pos = t.position; return new Vector2(pos.x, pos.y); } public static float ActualDistanceInWorld(this DistanceJoint2D dist) { return (dist.transform.TransformPoint(dist.anchor) - dist.connectedBody.transform.TransformPoint(dist.connectedAnchor)).magnitude; } }