遇见一个比较又意思的功能两点一线连起来 记录一下主要逻辑 target线 这个需要把中心点设置成1,0.5 target线对准的是中心点
public void SetTransformInfo(RectTransform start, RectTransform end, RectTransform target)
{
var Distance = Vector3.Distance(start.localPosition, end.localPosition);//两者之间的长度
target.sizeDelta = new Vector2(Distance, target.sizeDelta.y);
var RotateY = RotatAngle(start.localPosition, end.localPosition);
target.localEulerAngles = new Vector3(0, 0, RotateY);//设置旋转
target.localPosition = start.localPosition;
}
public float RotatAngle(Vector3 start, Vector3 end)
{
float x = start.x - end.x;
float y = start.y - end.y;
//求斜边长度
float hypotenuse = Mathf.Sqrt(Mathf.Pow(x, 2f) + Mathf.Pow(y, 2f));
//求出弧度
float cos = x / hypotenuse;
float radian = Mathf.Acos(cos);
//用弧度算出角度
float angle = 180 / (Mathf.PI / radian);
if (y < 0)
{
angle = -angle;
}
else if ((y == 0) && (x < 0))
{
angle = 180;
}
ret