Clickable object WITHOUT colliders?

Hi,

I know the easy way with OnMouseDown(), but this requires a collider. Basically I don't need any physics calculation, but only a popup-menu when clicked on an object. I have 1000 objects on screen (max.) and I want to make sure there are no unneeded calculations done in the background.

Any ideas?

Thanks.

There are many ways to implement picking. Here's a couple:

  1. When the mouse button is pressed, use Camera.WorldToScreenPoint() to transform the positions of all objects that are in front of the view plane into screen space, and then perform a circle or AABB check to see if the mouse position is sufficiently close to any of them.

  2. Perform the picking in world space using a ray-sphere check.

Either of these should work. The only consideration I can think of is that if the number of objects is large enough, brute-force methods like those described above may introduce a noticeable performance penalty.

With 1000 objects on a desktop computer, I think brute-force would probably be sufficient (you can always try it and find out for yourself).

Otherwise, you'd probably need to introduce a broad-phase culling step of some sort. Note however that the more complex the system becomes, the closer you'll get to simply duplicating the functionality that PhysX already provides.

you could try having the object in question check when the button is pressed and if it is check for the players distance and facing direction and if the player is facing the object and is within a certain range then send a message to the players gui script to show the menu.

so this isnt code just a draft of what it might look like

if (button pressed)
{
    if(player is within range && player is facing me)
    {
        get players gui script and tell it to show the menu
    }
}

if you have it check constantly instead of every time the player presses the button it'll cause lag so thats why I say wait till the button is pressed. hope this helps and good luck