Unity UGUI 两点一线

遇见一个比较又意思的功能两点一线连起来 记录一下主要逻辑  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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值