How can I make sure that when my character is in front of an object it is visible and when it is behind an object it does not “step” on it?! Like my character does in the image.
try to use triggers for each side with this kind of code:
using UnityEngine;
using System.Collections;
public class SortingOrderScript : MonoBehaviour
{
public const string LAYER_NAME = "TopLayer";
public int sortingOrder = 0;
private SpriteRenderer sprite;
void Start()
{
sprite = GetComponent<SpriteRenderer>();
if (sprite)
{
sprite.sortingOrder = sortingOrder;
sprite.sortingLayerName = LAYER_NAME;
}
}
}
hope it helps