Canvas Sorting Layer

I want to put in my script a line which change set order to my canvas.

https://unity3d.com/learn/tutorials/modules/beginner/2d/sorting-layers

Your canvas will need to have it’s render mode set to camera mode, you can do that through the editor or script:

Canvas myCanvas = this.GetComponent<Canvas>();
myCanvas.renderMode = RenderMode.ScreenSpaceCamera;
myCanvas.worldCamera = Camera.main;

Then the bit you probably need is below, this will set the layer and order within that layer:

myCanvas.sortingLayerName = "SortingLayerName";
myCanvas.sortingOrder = 1;
3 Likes

Thx

2 Likes