Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Hop solved! 

There are  2 different sorting layers. One that is behind the PNJ's, and one that is before it. I check the position of the player when I collide with PNJ's. If the player's position in y> to the PNJ's, then the player is behind it. 

It works fine but if 2 PNJ's  are too close to one another it doesn't work fine. So it's not perfect but it 's enough for now.


public SpriteRenderer Ren;
void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("PNJ") && other.transform.position.y > transform.position.y)
        {
            Ren.sortingLayerName = "PlayerDevant";
        }
        else
        {
            Ren.sortingLayerName = "PlayerBehind";
        }