Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Canvas Sorting Layer

Discussion in 'Scripting' started by ProGamerRo, Feb 9, 2016.

  1. ProGamerRo

    ProGamerRo

    Joined:
    Jul 1, 2015
    Posts:
    19
    I want to put in my script a line which change set order to my canvas.
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
  3. Zephni

    Zephni

    Joined:
    Apr 23, 2015
    Posts:
    100
    Your canvas will need to have it's render mode set to camera mode, you can do that through the editor or script:

    Code (CSharp):
    1. Canvas myCanvas = this.GetComponent<Canvas>();
    2. myCanvas.renderMode = RenderMode.ScreenSpaceCamera;
    3. myCanvas.worldCamera = Camera.main;
    Then the bit you probably need is below, this will set the layer and order within that layer:

    Code (CSharp):
    1. myCanvas.sortingLayerName = "SortingLayerName";
    2. myCanvas.sortingOrder = 1;
     
  4. ProGamerRo

    ProGamerRo

    Joined:
    Jul 1, 2015
    Posts:
    19
    Thx
     
    qkrwnsgh706 and eleltofik like this.