I would like to create an editor tool who can change the position of an object in the scene view into other object in the world, based on mouse position, like in the picture bellow (the red pyramid is my object to positionnate/rotate)
I would like to do a raycast from the scene view camera to the mouse position (or something like that), to get the gameObject over the mouse, and then get the position of the verticle / normal for position and rotation of my gameObject
For now, I have tryed some code who didn't work, I have my object named "preview", and inside the methode OnSceneGUI() in a editor script i have managed to move my preview object, but now I have to know where to put it... Thanks !
EDIT: here some of my try:
Transform previewPoint; //here my transform
void OnSceneGUI()
{
PointCreator();
}
private void PointCreator()
{
//test 1
Camera sceneCam = SceneView.GetAllSceneCameras()[0];
Vector3 spawnPos = sceneCam.ViewportToWorldPoint(Event.current.mousePosition);
previewPoint.position = spawnPos;
//test 2
Vector3 mousePosition = Event.current.mousePosition;
mousePosition.y = SceneView.currentDrawingSceneView.camera.pixelHeight - mousePosition.y;
mousePosition = SceneView.currentDrawingSceneView.camera.ScreenToWorldPoint(mousePosition);
mousePosition.y = -mousePosition.y;
previewPoint.position = mousePosition;
}