unity3d - Change Gameobject z position inside canvas to bring it forward -


i have 2d scene orthographic camera has canvas multiple gameobjects. these objects dialogs displayed user when click button.

all gameobjects pre instantiated , using setactive() display them or hide them. now, if user clicks on button, see gameobject expected, if click on button without closing previous window, new gameobject(ui window) displays below opened window.

the real way have found change switching gameobjects hierarchy order inside canvas. do, however, need change programmatically, regardless of that.

i have tried changing z values , adding spriterenders layers, keep seeing same order in unity editor. changes if drag gameobject , change position inside canvas hierarchy.

how can achieve via script ?

your problem when your're rendering inside canvas position of gameobject in hierarchy matters. canvas using order in hierarchy z-sorting.

but can affect order of gameobject in hierarchy in scripts, see transform.setsiblingindex, transform.setasfirstsibling , transform.setaslastsibling if want change position of gameobject in hierarchy


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -