OnMouseDrag() get mouse position in relation to Vector3.zero

Hi,

I’m doing something similar to a slider control, but instead of using the UI slider, I’m rezzing gameobjects and destroying game objects depending on which way you’re dragging your mouse.

In other words, take a prefab cube that’s longer than it is wide, and add clones of it on screen as you drag your mouse right. Remove the clones, 1 at a time, as you drag the mouse left.

This is in 3D though, so as soon as the orbit camera flips to the other side of orbit, left & right are now backwards from what makes sense.

I need to get away from left & right and establish a new rule - if the mouse is dragging towards the center of the world (Vector3.zero) then you’re removing clones. Conversely, if you’re dragging away from center then you’re adding clones.

My issue is properly detecting dragging towards world center and away from it in an OnMouseDrag() event.

Preferrably I’d like to get back a single float value which is Distance from mouse location to world center.

Can someone enlighten me?

Cheers and thanks in advance!

Found a possible solution, and although this seems dodgey to me because it does not do any screen to world conversions, it works. If you have a better solution please add it here, I’m all ears.

Effectively I just measure the Vector3.Distance() from Input.mouseposition to Vector3.zero.

If the current distance is more than the last frame’s distance, I increase the clones, and vice versa.