- Home /
z-Order on same game object some time in front some time behing Why ?
I got a list of Enemy coming from a prefab 2d with a layer and z-order all enemy got the same... it comes from the same prefab... In my game there are multiple spawn position (red lines) and some time closer enemy overlap each other... then problem comes when the enemy behind overlap the enemy in front (lower on the y axis). How can i make the lowest enemy in front always... this is a simple example some map has 4 road (red lines) and the enemies waves spwn randomly on the road... so it must be dynamic...
So i think about adding a script on my road and giving them a z order to pass to the enemy when instantiated...
Is there any better way to do that...
Answer by sath · May 02, 2020 at 07:59 AM
upon instantiation, as you already know the position set z order dependency from y position e.g z.order = y.position * -1f