Unity2d:为什么这个精灵的行为就像它在背景后面,即使它的 Z 值设置在 canvas 前面?

Unity2d: Why does this sprite act like it is behind the background even though its Z-value is set to be in front of the canvas?

Showing the general setup of the scene and where the sprite is

the sprite is "behind" the background but the Z-value should be correct

我已经尝试过改变 canvas 的渲染模式等解决方案;不同的选项不起作用,“World Space”将游戏视图变为默认背景颜色。经过一天的阅读 manuals/guides 并查看其他问题后,我无法弄清楚这一点。谢谢你帮助我!

问题是您正试图在 Canvas 对象上使用 SpriteRenderer。删除 SpriteRenderer 并改用 ImageRawImage 组件。

关于 UI 的另一个注意事项是,除非另有说明,否则您将不可避免地 运行 进入,否则 Canvas 层次结构中更靠下的对象将呈现在其上方的对象之上。

我也会避免更改所有对象的 z 轴。制作 Canvas 个具有不同排序层的组,以在彼此之上呈现组。在层次结构中按特定顺序放置对象以获得所需的绘制顺序。在 2D 场景中弄乱 z 轴可能会让人头疼,而且不是很模块化。如果您想稍后更改排序顺序,您为每个对象设置的特定 z 偏移量将需要更改。