Answer the question
In order to leave comments, you need to log in
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
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; } // если он выше
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question