I've got a scene with 10,000 GameObjects in it and I'm trying to implement Mouse Click object selection.
I've done this by doing the following:
- Attach a MonoBehaviour Component to the GameObject and override OnMouseDown().
- Add a Box Collider to the object to get mouse events.
I'm looking for a more optimal way to do this, something similar to this:
- When the user clicks the mouse, run a RayCast from the cursor location to see if it hits a GameObject. If it does, select that object.
Ideally, this logic only runs when the user clicks the mouse and I don't have to run OnMouseDown() on every one of my 10,000 GameObjects in every frame to determine a hit.
So the question I have is, which GameObject do I attach this script to so I only execute this logic when the user clicks the mouse? Or are there better ways to implement object selection?