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