Transform---将某物体旋转至鼠标位置

时间:2021-07-01 10:18:41
/// <summary>
    /// 让某物体转角到鼠标点击的位置
    /// </summary>
    /// <param name="RotateGO">需要转角的那个物体</param>
    public static void  RotateToMouseClick(Transform RotateGO)
    {
        Vector3 mousePos = Input.mousePosition;
        mousePos = Camera.main.ScreenToWorldPoint(mousePos);
        Vector2 targetDir = mousePos - RotateGO.position;
        float angle = Vector2.Angle(targetDir, Vector3.up);
        if (mousePos.x > RotateGO.position.x)
            angle = -angle;
        RotateGO.eulerAngles = new Vector3(0, 0, angle);

    }



某个点旋转某个角度后延某个方向运动运动十米

Vector3 newPos = this.transform.rotation * new Vector3(10f, 0f, 0f);