I have a game where holding the left mouse button makes the player float up into the air.
I've just added a GUI into the game.
I want to use an "Automatic Layout" using GUILayout, instead of a "Fixed Layout" using GUI.
This is because the "Automatic Layout" using GUILayout automatically sizes the GUI.
If I use a "Fixed Layout" using **GUI**, then I can use IsPointerOverGameObject to check if the mouse is over the GUI when clicking a control, so that the player will not float up into the air.
But if I use an "Automatic Layout" using **GUILayout**, IsPointerOverGameObject doesn't work, and the player will still float up into the air when clicking a control.
So why doesn't IsPointerOverGameObject work with the GUILayout's "Automatic Layout"?
And how can I achieve the same effect using GUILayout's "Automatic Layout"?
*Example of working code for a "Fixed Layout" using GUI:* if (Input.GetMouseButton(0)) { if (EventSystem.current.IsPointerOverGameObject()) {return;} // Detects clicks on the UI. rb.AddForce(Vector3.up * speed); // Thrust }
I've just added a GUI into the game.
I want to use an "Automatic Layout" using GUILayout, instead of a "Fixed Layout" using GUI.
This is because the "Automatic Layout" using GUILayout automatically sizes the GUI.
If I use a "Fixed Layout" using **GUI**, then I can use IsPointerOverGameObject to check if the mouse is over the GUI when clicking a control, so that the player will not float up into the air.
But if I use an "Automatic Layout" using **GUILayout**, IsPointerOverGameObject doesn't work, and the player will still float up into the air when clicking a control.
So why doesn't IsPointerOverGameObject work with the GUILayout's "Automatic Layout"?
And how can I achieve the same effect using GUILayout's "Automatic Layout"?
*Example of working code for a "Fixed Layout" using GUI:* if (Input.GetMouseButton(0)) { if (EventSystem.current.IsPointerOverGameObject()) {return;} // Detects clicks on the UI. rb.AddForce(Vector3.up * speed); // Thrust }