Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

Help Wanted Can I make 2D light affect a specific sorting order range?

Discussion in '2D' started by Tom-Kazansky, Feb 4, 2021.

  1. Tom-Kazansky

    Tom-Kazansky

    Joined:
    Mar 9, 2015
    Posts:
    14
    Hi,
    I want to apply 2D light effects to my 2D game so it could have day/night time.
    my game is a zombie shooting genre with main character on the left side of the screen, who will fight hordes of zombies coming from the right side of the screen.
    I divide the scene into "lanes" and the zombies will spawn on these lanes.

    when I tried to apply 2D light to the game, I ran into a problem, a light from a lane will affect sprite which it wasn't supposed to affect.
    please check this image:
    upload_2021-2-4_11-21-29.png
    - the light affects the zombie A => this is expected
    - the light also affects zombie B => this is the problem, the light should not affect zombie B.
    zombie A and B have different sorting order value.
    The light can affect specific sorting layers but I don't see any option to make it affect specific sorting range (example: affect range: from -100 to 100, then sprite in sorting order 150 will not be affected)

    after searching around, I stumbled upon this post which has this result:

    I think this is what I want.
    the solution involves modifying a shader and I don't know anything about shader :(
    can anyone point me a direction to solve this?
    if modifying the shader is too hard, can I modify the 2D light script to add a range of "target sorting layers" ?

    Thank you for reading,
    Tom.
     
unityunity