Determine point in world space from mouse in Scene View


Is there any way (that works) to return the coordinates of where the cursor is on the Scene View in the editor? I'm trying to effectively make a painting script for the editor. I've been working on this for nearly 4 hours, but nothing seems to get close to working.

The general thought is: 1) Trigger on mouse-click or key press (key press apparently requires a menu item so you can use a shortcut, but then that requires the function to be static) 2) Grab mouse location (you could use handles, you could use events, you could use camera...) 3) Ray cast from that point into scene 4) On hit, grab the point ( 5) place prefab from AssetData at point, or whatever)

Any ideas? I would post code but I keep reworking it to the point where I now have nothing much to post.



I seem to remember the active camera (which can also be the Editor camera) can be accessed via Camera.current. If that is true, you can use your standard method to find the hitpoint (camera.ScreenpointToRay, Physics.Raycast, ...). Not a complete answer, but it should point you in the right direction - which is the intention of UnityAnswers anyways ;-)