Day 16: From Prototype to Work of Art

From Cubes and Capsules to Art!

Objective: Remove all primitive objects and add 2D art.

With assets we can make this simple game look beautiful. The first thing we will do is add a background.

Now it looks like we are in space!

Next step will be to change the player over to a 2D sprite. First thing we will do is add the image to the hierarchy and scale it down to .5 on all axis.

Let’s transfer all the components over from the old player to the new. We will be using 2D box collider. In this process we will make sure we tag the new player as Player.

If you play the game now, you may notice that the player can go behind the background image to fix that we will go under the sprite renderer. Click the drop down for sorting layer and click add sorting layer. Here we will add a background and foreground sorting layers.

Back on the player make sure the sorting layer is set to Foreground.

For the background sprite, make sure the sorting layer is set to background.

When we added the box collider, it will be to large for the sprite, what we will do on the player is edit the collider and make sure it fits just round the sprite.

And that’s the end for the player, we will do the same idea for the enemy and laser. The enemy will just use a different sprite and add rigidbody2D. Box collider will need to have trigger checked. Sorting layer will be foreground as well. The rigidbody will need gravity set to 0.

We’ll start a laser again. Add the laser sprite into the window and copy all the components needed but the 2D versions. We will swap out the capsule collider for a box collider 2D.

We will turn this into a prefab and assign the prefab to the player’s reference for the laser to fire.

Now it is time to fix the script. On the Enemy script we have to change all the OnTriggerEnter to OnTriggerEnter2D.

Changing the OnTriggerEnter to it’s 2D version.

The last thing we need to do is adjust the offset of the laser’s instantiate position. We will hit play fire once and hit pause. Here we will move the laser where we need to and copy the position and add to the player script. We offset the position on the y by 1.4.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Tyler Smallwood

I am passonate on learning to program and use Unity to become a skillful Unity Developer