Question by
kurpnieks2 · Feb 26, 2016 at 03:07 PM ·
vector3
Vector3 from mouse position in scene view in edit mode
Hello,
I have been trying to learn how to get a Vector3 from mouse position from scene view in edit mode when I press a key. I have tried to combine it with custom Menu Items, which I would use to make scene editing more comfortable.
I have tried to use Camera.current() aswell as HandleUtility.GUIPointToWorldRay() to do that, yet when i try to use it, I get the message "Object reference not set to an instance of an object".
Can you tell me what I have been doing wrong?
Here are the both code versions that I tried to do the work with, I will be very thankful if you can help me with this.
[MenuItem("My Commands/Custom Command _b")]
static void c_Command()
{
Vector3 position = Camera.current.ScreenToWorldPoint (Event.current.mousePosition);
Debug.Log (position);
}
[MenuItem("My Commands/Custom Command _b")]
static void c_Command()
{
Vector3 position = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition).origin;
Debug.Log (position);
}
Comment