In unity, I want to use code to control the hierarchical display, but I can't find it?

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

  1. Make sure the Canvas selects Screen Space - Overlay in Render Mode

  1. Make sure you belong to the same hierarchy

  1. 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!

Guess you like

Origin blog.csdn.net/weixin_52890053/article/details/129263389