在2D设计器下,想实现人物前后关系就不能依靠Z轴了,需要根据Y轴(高度)来调节layer的深度。

if(this.transform.position.y<0) { this.GetComponent<SortingGroup>().sortingOrder = (int)Mathf.Abs(this.transform.position.y * 10); } else { this.GetComponent<SortingGroup>().sortingOrder = (int)(this.transform.position.y * -10); }
很简单的,只需要将以上代码写入Update,并绑定至物件中即可,如果物件不使用SortingGroup组价,可以修改至对应的渲染组件。
关于能效问题,可以考虑使用碰撞体来检测物件是否越过另一个物件,再修改深度。
Comments | NOTHING