would i could make a gameobject follow by mouse on editor mode?

Hello,guys,

I want to make a builder tool on editor mode(not runtime),so I want to make a prefab follow mouse to place.

I check some scripts on runtime mode,the logic looks OK.

When i use Camera.main to calc ray ,it works fine.

but i notice on editor mode ,some SceneView.GetAllSceneCameras() ,i test it,but it can locate correct position.

Thanks!

Ray r = SceneView.GetAllSceneCameras()[0].ScreenPointToRay(Input.mousePosition);

Vector3 p = GetIN(r.origin, r.direction, Vector3.zero, Vector3.up);

PlacePrefab.transform.position = p;

Is Input.mousePosition reporting the correct values in editor mode? I feel like I’ve read in the past that you need to use a different method to get mouse position for the Scene view.

It’s a bit odd to get the mouse position in the editor scene view, but this worked for me:

Vector3 mousePosition = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition).origin;

You may also need to set mousePosition’s Z-value to 0 if you’re editing in 2D mode.

1 Like