RayCasting multiple objects in a stack?

I’m working on an RTS style game and have the following script for selecting objects:

Ray ray = Camera.mainCamera.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if(Physics.Raycast(ray, out hit, Mathf.Infinity))
{
   //Handle Input.
}

However, due to the nature of the game, I want the player to be able to select from a group of objects which are placed at the same transform.position, some of which are hidden with a boolean value.

I want the player to be able to click on the stack and then select one of the objects which isn’t hidden.

Where’s a good place to start with this?

Many thanks!

Hello there!

Have a look at the Physics.RaycastAll function. It returns an array of all Hits on the line, that would be all the objects in your stack.

Thanks Myx! That was exactly what I was after.

I’ll browse my intellisense and the knowledgebase before posting again… :slight_smile: