I am making a 2D game where the player is on the left side of the screen. Enemies spawn on the right side in 4 different spots and come towards the player in 4 separate lanes. The player is able to move up and down between lanes to shoot these enemies.
This is a 2D game but it appears to be in a 3D space because the enemies overlap each other when coming down the lanes.
My issue is that the player needs to move between layers depending on which lane he is in. For example, if he is in the first lane (closest to us, the gamer) he would be on the top layer. Then I need him to step back a layer when I press the up arrow because I need him to move to the next lane so that the enemies in the first lane would be on the layer above him and the enemies in the lane behind him would be behind him and so on.
How would I do this in C#?
Thanks in advance!
Any particular reason you can’t use the Z axis as your sorting depth?
I need the player to be able to move between the layers so that it appears he’s shifting through the lanes. Does that make sense?
Enemies in the lane behind the player need to be behind him and enemies in the lane infront of him need to appear to be in front of him. But I can’t do that if the player is just on one layer, he needs to shift between lanes which will change which enemies are in front and which are behind.
monsters on lane 1 could have a z position of 1, monsters on lane 2 have z 2 etc., then just switch the z-position of the player whenever he switches lanes.
I tried that. But it still doesn’t work. The sorting layer seems to be superior to z axis. Because the enemies will be above my character on the z axis but it still depends on the sorting layer to where the objects appear
can’t you just put the player and enemies all on the same sorting layer?
GameObject.layer might do the trick.
But I think others are right, it’s best to have your GameObjects changing lanes through Z axis instead of layers as it would allow you to add a smooth transition between lanes.