KeyboardMouse

KeyboardMouse
– Draw Circle by GLPrimitiveTypes (Space-Key to change types)
– Draw Quad With Mouse Clicking
– Free-Draw Line With Mouse Dragging
– Rotate Cube With Mouse Horizontal/Vertical Movement
– Select Object With Mouse Clicking (mouse clicking on the empty space to unselect)

KeyboardMouse

 

Unity Camera.ScreenToWorldPoint

Unity – Scripting API: Camera.ScreenToWorldPoint (unity3d.com)
Camera 클래스의 ScreenToWorldPoint 함수는 스크린 좌표를 카메라가 찍고있는 3차원의 좌표로 바꿔줌.

void OnGUI()
{
        Vector3 point = new Vector3();
        Event   currentEvent = Event.current;
        Vector3 mousePos = new Vector3();

        // Get the mouse position from Event.
        // Note that the y position from Event is inverted. (GUI space -> Screen space)
        mousePos.x = currentEvent.mousePosition.x;
        mousePos.y = Camera.main.pixelHeight - currentEvent.mousePosition.y;
        mousePos.z = Camera.main.nearClipPlane; 
        point = Camera.main.ScreenToWorldPoint(mousePos);

        GUILayout.BeginArea(new Rect(20, 20, 250, 120));
        GUILayout.Label("Screen pixels: " + cam.pixelWidth + ":" + cam.pixelHeight);
        GUILayout.Label("Mouse position: " + mousePos);
        GUILayout.Label("World position: " + point.ToString("F3"));
        GUILayout.EndArea();
}