Search Unity

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:
    476
    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:
    8,336
    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:
    476
    But UI elements dont have any sorting layer, so how can you layer that??
     
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,336
    Canvas has a sorting layer.

     
    resifrog, Gng357 and jhocking 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