21 lines
712 B
C#
21 lines
712 B
C#
using UnityEngine;
|
|
|
|
public static class Extensions
|
|
{
|
|
public static ComponentA GetOrAddComponent<ComponentA>(this GameObject gameObject)
|
|
where ComponentA : Component {
|
|
|
|
ComponentA result = gameObject.GetComponent<ComponentA>();
|
|
return result == null ? gameObject.AddComponent<ComponentA>() : 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;
|
|
}
|
|
}
|