Change the render order of two GUI Images in script

I have two different GUI image objects. They are rendering in the order they are in the scene (lowest on top). However, I want that if a user touches one that it moves to the top.

How can I change this order in the script?

I’ve experimented with OnGUI and GUI.depth to no noticeable change.

The only way I’ve been able to figure out so far is to remove the object from the scene and re-add it, but this seems incredibly wasteful.

Does anyone know a better way that I am just missing?

Thanks!

You can use Transform.SetAsFirstSibling, Transform.SetAsLastSibling, and Transform.SetSiblingIndex to change object order.