Skip to content

[Unity] Use SortingIndex() To Change the Order of Objects in the Specific Layer

Last Updated on 2021-10-30 by Clay

To make the SortingIndex() function effective, we need to set the Sorting Layer.

And the Order in Layer is the order we can change with program. The higher number, the higher layer the object will be, and the non-transparent objects will cover the below objects.


Sample Code

In order to specify the order in the layer, we need to use the SpriteRenderer property of the object. Assume the order is i:

為了要指定在層(layer)中的順序,我們需要使用物件的 SpriteRenderer 屬性。在指定順序為 i 的情況下:

gameObject.GetComponent<SpriteRenderer>().sortingOrder = i;



References


Read More

Tags:

Leave a ReplyCancel reply

Exit mobile version