From Prototype to Work of Art

Game using cubes and capsules

Objective: Move from basic shapes to game assets

So far the space shooter project has been made up of cubes and capsules but that’s not really what we want in a game. Unity makes it very easy to add art and game assets to the project and swap out the simple cubes and capsules we’ve been using as we built out the basic prototype.

We’ll start by adding a background by adding a 2D sprite to the hierarchy and positioning the sprite to match the scene. Next we need to set the sorting layers. In 2D sprites and game objects will appear on top of each other depending on which assets have the higher value in the sorting layer. You can set multiple layers such as background and foreground to seperate the assets and then assign the order in layer to each asset within its grouped layer.

New background added

With the player, since it was a 3D cube, we just add a new player ship sprite to the hierarchy and add the player script, tag it as player, assign the laser prefab to the script in the inspector then delete the older player.

Our new player

Next go to the enemy prefab and because its a 3D object, remove all but the enemy script so we can rebuild it as a 2D game object.

Old 3D enemy prefab
New start for enemy prefab

Next add a sprite renderer to the enemy prefab and add the sprite. Now because we’ve changed the game object we need to add a new Rigidbody 2D and Box Collider 2D to the enemy and a Box Collider 2D to the player. Turn the gravity scale off in the rigidbody as we are using programmed movement and not gravity and set both colliders to is trigger. After that open the enemy script as on trigger enter only works for 3D so we need to do a fix up for 2D. Here OnTriggerEnter becomes OnTriggerEnter2D and Collider becomes Collider2D, seen below.

2D collision edit

Finally rebuild the laser. Bring in the sprite, add a rigidbody 2D and collider 2D like before, set the gravity to off and as isTrigger. Now delete the old laser prefab and make this new laser into a prefab. Set the sorting later and tag then assign the new laser prefab on the player script in the inspector. Now it’s looking more like a game.

Game running with new assets