Upgraded to 2.5.1 and I’m still getting raycasts firing off even when the mouse is down over a gui button.
If you want to test it, create a plane 200x200 and align the main camera to view it. put these scripts on an EmptyGameObject and run. I angled the camera so there was some plane visible for a hit and some “sky” visible for a no-hit. Also, the “100” button was OVER the plane so it could register a hit if clicked through.
When I click on the 100 button, I get a mix of “100” and “Hit Something” printed on the console. Sometimes I click without getting “Hit Something” but mostly it registers the button hit and the collider hit.
Adding Event.current.Use() to the button click makes no difference. I’m temporarily averting this by adding a full screen button that captures “raycast clicks” and tells the raycast to fire but I’d like to know if this is a bug or working as intended. If it’s a bug, I’ll bug report it.
Anyone from UT have any input?
Thanks,
Jason
code below:
raycast.js
function Update () {
if (Input.GetMouseButtonDown(0))
{
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, 1000)) {
print ("Hit something");
}
else
print ("Hit Nothing");
}
}
button.js
function OnGUI ()
{
GUI.depth = 100;
if (GUI.Button (Rect(400,400,100,100),"100"))
{
Event.current.Use();
print("100");
}
}