You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
902 B

using UnityEngine;
public class Sorting : MonoBehaviour
{
public Transform player;
// Update is called once per frame
void Update()
{
if (transform.position.y >= player.transform.position.y)
{
//Debug.Log("behind player");
GetComponent<SpriteRenderer>().sortingOrder = (player.GetComponent<SpriteRenderer>().sortingOrder) - 1;
GetComponents<BoxCollider2D>()[1].enabled = false;
GetComponents<BoxCollider2D>()[2].enabled = true;
}
if (transform.position.y < player.transform.position.y)
{
//Debug.Log("in front of player");
GetComponent<SpriteRenderer>().sortingOrder = (player.GetComponent<SpriteRenderer>().sortingOrder) + 1;
GetComponents<BoxCollider2D>()[1].enabled = true;
GetComponents<BoxCollider2D>()[2].enabled = false;
}
}
}