When Canvas selects Screen Space - Overlay in the rendering mode (Render Mode), it is impossible to modify the hierarchical relationship by modifying the value of the Z axis at this time, but you still want to solve it? It's still very simple, just one line of code. See below for details:
1. Two methods of changing the hierarchical relationship under Transform
1. SetAsFirstSibling: Used in the UI, when this method is called, the current game object can be set to the first layer of the same layer game object
2. SetAsLastSibling: Used in the UI, when this method is called, the current game object can be set to the last layer of the same layer of game objects
Two, use
Make sure the Canvas selects Screen Space - Overlay in Render Mode
Make sure you belong to the same hierarchy
Create a script and mount it. Type in the code: SetAsLastSibling/SetAsFirstSibling (according to different needs, choose what you need)
Therefore, if you want to use code to control the display of hierarchical relationships, but do not want to change the original hierarchy and layout. Then you might as well try: transform.SetAsLastSibling/transform.SetAsFirstSibling/These two methods that come with Transform!