How do I find the object below the current one in the heirarchy?

Okay, so I’m making a space game set in the solar system, and due to the immense scales involved, I’m rendering the planets as 2D images in the GUI whose positions are projected onto the canvas based on the position of an empty object representing the planet in the game world. So far, I’ve only added the sun and Mercury. My problem is that Mercury’s icon will still render in front of that of the sun even when the object is behind the sun relative to the camera. I figure I can fix this by adding a script that will check the position of the celestial body that’s next in the hierarchy and jump down the list if it’s closer than that. However, I’m not sure how I should go about finding the next thing on the list, since it seems I can only retrieve the sibling ID of the object calling the function. Does anyone know how I might go about doing this?

Consider the following:

  1. Use real 3D scene and scale the planets visually so to mitigate the immense scales involved.
    or
  2. Use “Sprite Renderer” instead of Canvas. For sprites you can set “Order in Layer” from code depends on distance from camera to “an empty object representing the planet in the game world”: sort items by distance and then assign values for order from the beginning of the sorted list like 0,1,2,3,…
    or
  3. If still with Canvas approach, then use “SetSiblingIndex” method to re-arrange planets which should be in common parent GameObject (container). Sibling indices are set still depends on the distance from the camera (as in (2)).