RaycastAll related question

Hello everyone,

I have this code:

GameObject GetClickedGameObject()
	{
		Ray ray = MyCamera.ScreenPointToRay(Input.mousePosition);
	if(Physics.Raycast(ray,out hit))
		{
	return hit.transform.gameObject;
	}
		else
		{
			return null;
		}
	}

Which shoots a single ray and as soon it hits an collider it returns the info.
The problem is, that if I have another colider in front of the tageted colider, it will not work anymore.

How can I use the RaycastAll to search for that specidifc colider I’m interested in?
The info i’m passing further for processing is stored in: hit.transform.gameObject

Thank you.

  1. raycastAll
  2. foreach transform in raycast result
  3. if transform.name == something
  4. you got it