using System.Collections; using System.Collections.Generic; 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 DistanceInWorld(this DistanceJoint2D dist, Vector2 pointInSelf, Vector2 pointInConnected) { return (dist.transform.TransformPoint(dist.anchor) - dist.connectedBody.transform.TransformPoint(pointInConnected)).magnitude; } }