T
T
T1cKz2020-09-28 22:10:30
Unity
T1cKz, 2020-09-28 22:10:30

Unity 2D How to make the player be able to go visually behind the "wall"?

For example, I have an object - Table
And you can go behind it, both in front of it and behind it.
But the problem is that when the character is in front of him, the table is behind, and when the character is at the table, he seems to be standing on it, i.e. to. the "Hero" layer is in front of the "table" layer... The
question is how to make it so that when the player is at the table (Rising above the center of the object), the table is already rendered in front of the player?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
T1cKz, 2020-09-28
@T1cKz

UPD: I decided
For those who need it, this is work with Order in Layer
I did it with a crutch through the ass, but
Let's say the center of the object is at coordinate 5.1

public GameObject Table;
public GameObject Player;

void Update()
{
   if(Player.transform.position.y < 5.1) { Table.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 0; } // типа если игрок ниже стола
else { Table.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 1; } // если он выше
}

ps if anyone has a better way / improve it - write, I will be glad

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question