I am moving forward with my dungeon/housing creation system and have come across another issue, I have read a few ways on here regarding making gui ignore raycast. The method I was attempting was somewhat as follows:
It worked great for my background gui elements, but buttons would still fire through on clicking them. I have read about using a GUI Texture behind it but have yet to see any examples. Also had no like trying the tooltip method - I was hoping to be pointed in the right direction or hopefully someone has a working project that tackles this?
I can post the code if necessary although I removed everything that had to utilize this, it is quite large and tangles between many different scripts so will be quite a bit of work just to make readable.
You can define two rectangles (one for each menu) in pixel coordinates, and disable raycasting when the mouse pointer is inside any of these rectangles:
var rMenu1 = Rect(20,200,180,400);
var rMenu2 = Rect(100,80,500,170);
function Update(){
...
var mousePos = Input.mousePosition;
ignoringRaycast = rMenu1.Contains(mousePos) || rMenu2.Contains(mousePos);
...
I’m assuming that ignoringRaycast == true disables raycasting.
If you’re using GUI.Box to draw the menus, rMenu1 and rMenu2 will be the same rects that define the vertical and horizontal menus - or you can even define bigger rects, so raycasting will be disabled when the mouse gets near to the menus.
Your solution works, but for if you are using a GUILayout window (like one that can be dragged around) youll find that the y position is wrong. heres my quick fix if someone is still struggling
var windowRect = new Rect(0,0,200,200);
mousePos.x = Input.mousePosition.x;
mousePos.y = Screen.height - Input.mousePosition.y;
ignoreRaycast = windowRect.Contains(mousePos);