is there a fallback OnMouseDown() options available?

i have some game objects that catch OnMouseDown() and its working fine.

but i’d like to catch OnMouseDown() events when the user clicks outside of gameobjects that have an OnMouseDown() handler.

is there a base, kind of catch all OnMouseDown() that triggers if i click outside of one of these special objects?

sorry if i haven’t phrased the question well, i’m kind of new to this

thanks

Input.GetMouseButtonDown.

–Eric

where would i put that? i already tried it in the camera update but it catches every mouse down, even ones going to the gameobjects, and that’s not what i want

thanks

Probably the simplest way to solve that would be to not use OnMouseDown, but use raycasting instead. (OnMouseDown is doing raycasting behind the scenes anyway.) So you do

if GetMouseButtonDown
    do raycast
    if raycast hits
        interact with hit object
    else
        clicked outside gameobjects

–Eric

1 Like

Put a big invisible collider on the screen to catch everything else. Works great with the event system.

ok, thanks, what object would i place in the scene at attach the collier to? i would like to get an event when i click on the sky, is that possible?

It’s actually easier and more efficient to do what I suggested. :wink: Putting a collider behind things can work in specific cases, where the camera basically doesn’t move much.

–Eric

If you are using OnMouseDown, then yes. However as soon as you add in the UI system then I find it easier to direct all of the clicks through the EventSystem.

The EventSystem is open source. So you can break it open to provide an event if no objects are clicked on.

A camera space UI element at the edge of the far clipping plane will work.