My 90 day journey becoming a Unity game developer: Day-11

Rhett Haynes
3 min readJun 3, 2021

--

Today we transfer from our prototyping stage to our production stage. We will start with adding a background to our space shooter.

To begin with, drag the background sprite into the Hierarchy. If the background sprite doesn’t fill up the entire screen, go to the Rect tool and pull the edges outward to fill up the screen.

Background added to the game.

Next, drag your player’s 2D sprite into the Hierarchy. If you notice while moving your player around the screen, the player isn’t always drawn on top of the background. The reason for this is that we need to adjust the order layers to put the player on top of the background. Remember when working in 2D using layers with sprites, the higher numbered sprites will be placed over the lowered number sprites on screen. Let’s set the player’s order layer to 1, and the background’s layer to 0.

Adjusting the player and background layers.

You can also create layers that will organize and show the game objects on the screen according to which layer is being used. According to the layers named in your list, the first layer will have the lowest number, and the last layer will have the highest number. If you want to change the order, you must click the drop-down arrow on sorting layer, click Add Sorting Layer, then flip-flop the named layers into the order you want.

Showing the difference between new layers created for background and foreground.

After creating our layers, using our new player we will add our player script to it. Also, we will go to our 3D player cube and copy the script component values. We then go back to our new player, and paste the component values onto the script. Change the new player’s name to “Player”, and add the Player tag as well. We can delete the 3D player cube since we have no use for it anymore.

Created 2D player to replace our 3D prototype.

Let’s scale down our spaceship to 0.5 which is a more manageable size. Plus, make sure the player is on the Foreground sorting layer. Delete the enemy from the Hierarchy since we have a prefab of the enemy.

Player scaled down and foreground sorting layer selected.

Last, if we play the game right now we will see that our player can’t collide with the enemy anymore even though our lasers can destroy the enemies. This is happening because we changed our player to 2D which doesn’t have any colliders attached to this sprite.

2D player battling 3D objects with no colliders.

We must convert our lasers and enemies into 2D game objects.

--

--