I am working on a tool for unity and I am trying to reproduce the painting tool used in Unity Terrain.
I succed to display a circle above my mouse to show where it is going to happen thanks to those lines:
void OnSceneGUI(SceneView sceneView)
{
Event evt = Event.current;
if (evt.keyCode == KeyCode.LeftAlt) return;
Ray ray = HandleUtility.GUIPointToWorldRay(evt.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, Mathf.Infinity))
{
if (evt.IsMouseButtonDown(0))
OnMouseButtonDown(hit);
if (evt.IsMouseButtonDrag(0))
OnMouseDrag(hit);
// I am repainting the scene on every mouse movement or else, the DrawWireDisc do not follow the mouse position smoothly, I do not know if there is an other way of doing that
Handles.DrawWireDisc(hit.point + cursorOffset.value, Vector3.up, cursorRadius.value, 2f);
sceneView.Repaint();
}
if (evt.IsMouseButtonUp(0))
OnMouseButtonUp(hit);
}
As you can see on the first lines, I added an if statement if I press the LeftAlt input to prevent the code to continue BUT it doesn’t not work and I don’t understand why.
if (evt.keyCode == KeyCode.LeftAlt) return;
I added a Debug.Log after this statement to see if the code running if I press the key and yes, it is still running.
Debug.Log(evt.keyCode == KeyCode.LeftAlt);
What is very strange is when I move my mouse, it debugs False. If I press LeftAlt it debugs True but if I do both, moving my mouse in the scene and pressing the LeftAlt, I have 2 debugs printing True and False instead of one.
Do you have any idea why it is doing that?