Mouse Click Handled At Wrong Level

I’m using GUI DrawTexture and DrawButton to create menus that pop up on top of each other. Right now I have a DrawTexture with a TextField label for a lower menu level followed by a DrawButton over top, but a little offset, from the layer below. When I click the button, the text in the TextField underneath is selected, instead of clicking the button.

If I don’t draw the text, the button works fine. If I draw the button before the text, the button works fine, but the text is drawn over the button.

How do I make the button drawn on top and make it the first item to handle a mouse click at that position?

You should probably be using Unity’s Canvas object for your UI needs. I’m not very familiar with the old GUI system but you should be able to disable raycasting against the text object, so that it won’t intercept the click event.

I think I tried using a canvas at first but ran into trouble with having custom textures in the UI. I’ll have to look around more at canvas information.

Just got buttons working in a canvas, looks like they work just fine without objects below the top object getting clicked. Thanks!

1 Like