Day 10: From Prototype To Work Of Art

Gerald Clark
4 min readApr 11, 2021

We finally have the basic functionality of our game fleshed out. We’re firing lasers and spawning enemies! Lets make our game look pretty now!

The artist on your team has provided some visual assets such as a background and some sprites! First we will put our background sprite in the game. Simply navigate to the folder your background is located in, and drag it into the hierarchy. Resize as needed. You may notice that the player and the enemy cubes look like they are behind the background. This is where layering comes in handy. Navigate to your background in the hierarchy. Find the Sprite Renderer component and go to “sorting layer”.

Yours probably has “default” as the only option. Click the drop down menu and click the “+” sign. Create a “background” and a “foreground” layer. Assign your background the background layer.

You’ll want to assign your player and your enemy the foreground layer. You cant do this yet though. We need to convert the 3D game objects to 2D Sprites. There are a few ways to do this.

REBUILD FROM SCRATCH:

Probably my favorite way to accomplish this. Lets import the sprite for our player. Navigate to the folder where your “player_turn_left0000” sprite is. Drag this into the hierarchy view. Our ship has appeared!

Rename it to Player and tag it “Player”. You’re going to need to add the following components:

The sprite renderer is where you will set the foreground layer. Add your player script that you also have on the cube. The box collider 2D component is needed as well.

Right now we have a 3D box collider on our cube game object. This isn’t going to work with a 2D sprite. We will also need to adjust our Enemy Script. Instead of using the OnTriggerEnter() function we need to change it to OnTriggerEnter2D(collider2D other).

This way the collider will actually function properly. Make sure to set IsTrigger to true!

Lets drag our EnemyTurnLeft sprite into the scene now too! It can be found in the following location:

We will need all the same components except the Player script. Instead add the enemy script. We will also need a Rigidbody 2D for the collisions to work! Make sure the Box Collider 2D is set to is true. On the Rigidbody you’ll need to set the gravity scale parameter to 0.

You can delete your prototype cubes. If you run your game you should be able to move your new ship sprite and have significantly more dangerous looking enemies spawning. As you can see your laser wont collide with them. Lets convert it to 2D as well. The laser will also need a Rigidbody 2D component.

Be sure to adjust the size of your box colliders to fit the game object like this:

The colliders need to fit around your objects nicely so that collisions are more believable.

Be sure to prefab your new enemy and laser. Now that all that is set up, we have a very nice looking game put together so far!

Before:

AFTER:

--

--

Gerald Clark

Father Game Developer Music Composer Sound Designer