Unity SceneView 鼠标转世界坐标

编辑器下SceneView鼠标位置转换世界坐标位置。两种方式:

var ray = Camera.current.ScreenPointToRay(GetMousePos());

            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, 10000) == false)
                return;

            var worldPos = hit.point;






private Vector2 GetMousePos()
        {
            var mousePos = Event.current.mousePosition;
            mousePos.y = Camera.current.pixelHeight - mousePos.y;
            return mousePos;
        }
Ray worldRay = HandleUtility.GUIPointToWorldRay(current.mousePosition);
            RaycastHit hitInfo;
            if (Physics.Raycast(worldRay, out hitInfo))
            {
                var pos = hitInfo.point;
            }

 

posted @ 2022-07-13 10:43  【Winco】  阅读(277)  评论(0编辑  收藏  举报