- Home /
Determine point in world space from mouse in Scene View
Hello,
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.
Cheers,
Unislash
Answer by Wolfram · Feb 03, 2011 at 10:39 AM
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 ;-)
Yes, I've worked with that thought process. There are two problems: First, if you want there to be a hotkey functionality as i do, you either need to add the script to a menu (which requires it to be static, and then can't use the camera functions) or invoke OnSceneGUI, which i can't seem to get working at all. Then you need to get the mouse position, and to do this via editor you need to use Events, which I also can't seem to get working at all. Guidance would be appreciated :-)