nix86
nix86

Reputation: 3037

How can I put a UI Image always on top in Unity 3D

I have noticed that in a canvas the elements are drawn from top to bottom so the image above is covered by the image below. The problem is that I want an ui image that is not the last sibling of the canvas to stay on top of all the others. How can I do?

Upvotes: 2

Views: 11846

Answers (3)

Cool guy
Cool guy

Reputation: 381

I would do an edit on Ethan's answer but seems the edit queue is filled so I'm writing it here. The CanvasGroup solutio does not work. Your other choice aside for changing the sibling index (hierarchy position) is to create a new Canvas, and have it override it's parent canvas's sorting order and add some offset to the new canvas's sorting order. Here's how you'd do it by hand in inspector: enter image description here

I've also created this simple script/component that does the job dynamically : enter image description here

Upvotes: 0

Ethan Choi
Ethan Choi

Reputation: 2399

I think you can try two ways.

First.
Use Transform.SetAsFirstSibling() to put the UI Component on top

Second.
Use CanvasGroup.sortingOrder to help your UI Component grouping.

Ref
http://docs.unity3d.com/Manual/class-CanvasGroup.html http://docs.unity3d.com/ScriptReference/Transform.html

Upvotes: 3

Milad Qasemi
Milad Qasemi

Reputation: 3049

there are couple of functions you can use for setting orders

Transform.SetAsFirstSibling

Transform.SetAsLastSibling

Transform.SetSiblingIndex

Upvotes: 1

Related Questions