x


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

more ▼

asked Feb 03 '11 at 10:09 AM

Unislash gravatar image

Unislash
74 9 10 19

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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 ;-)

more ▼

answered Feb 03 '11 at 10:39 AM

Wolfram gravatar image

Wolfram
9k 8 20 52

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 :-)

Feb 03 '11 at 07:15 PM Unislash
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3465
x349
x89
x58

asked: Feb 03 '11 at 10:09 AM

Seen: 1629 times

Last Updated: Feb 03 '11 at 10:09 AM