Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Need help putting a UI button on top of sprite.

Discussion in 'Getting Started' started by witcher101, Jan 14, 2016.

  1. witcher101

    witcher101

    Joined:
    Sep 9, 2015
    Posts:
    516
    I wana make UI button and UI image on top of 2d sprite.
    But no matter what layer i select or sorting layer i use UI always seems to appear behind sprite.
    Anyway to make it appaer in front of it.
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    It should be doable if you set your sorting layers properly. I have UI on top of sprites in my MiniScript demo, for example. I have my sprites in the Default layer, and my UI Canvas set to use Screen Space - Camera, sorting layer Default, Order in Layer 0. Importantly, the Plane Distance is set to 10, which is also the distance from my camera to the Z=0 plane. If I set the canvas's Plane Distance to more than 10, then it pops behind the sprites (which are at Z=0).

    (I also have a second canvas for the background, which is also using Screen Space - Camera at a plane distance of 10, but I set its Sorting Layer to Background, so it appears behind everything.)
     
  3. witcher101

    witcher101

    Joined:
    Sep 9, 2015
    Posts:
    516
    But UI elements dont have any sorting layer, so how can you layer that??
     
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Canvas has a sorting layer.

     
    Elmstrom, art092, resifrog and 2 others like this.
  5. X_HeavyHippo_X

    X_HeavyHippo_X

    Joined:
    Sep 27, 2019
    Posts:
    1
    wow dude you posted that 5 years after you joined