Now that my space shooter prototype can handle infinite waves of enemies by using coroutines it’s time to start using assets that are destined for the production state of the game.
Here are some ways to get game assets for Unity:
- You can make them from scratch using a specialized software.
- You can buy them in the Unity asset store.
- You can use Filebase, a plugin for Unity editor made by GameDevHQ that contains thousands of ready-to-go game assets for your game.
In my case, I’m using professional assets from Filebase, so I imported the packages for my game into my project folder:
To have a reference, this is how my prototype of the space shooter looks like in the game and scene views:
First, this game is intended to be 2D, so I need to change from 3D to 2D in the scene view:
Then, to make the background look like the space, let’s drag a sprite that fits the requirements and rename it into the scene:
Once we have the desired background we need to fit it in the scene and game view by using the rect tool:
A good practice to work with Unity is to create layers for the different types of assets in the scene. For instance, we need to create one for the background and one for the foreground so that the space sprite doesn’t show over the player, the enemies, the lasers or the UI.
Then, to upgrade the player from a 3D primitive box to a 2D sprite, let’s copy the script component of the player gameobject in the inspector and decide the sprite that the player will be:
Once we decide the sprite for the player, we can delete the 3D primitive box and drag the new player asset into the hierarchy.
Note: don’t forget to rename the gameobject and to choose the correct tag for the player as it’s an important property to check for collisions.
Select the appropriate layer for the new player gameobject so that it shows over the background:
Resize the player as you wish, the scene and game view will look like this:
If we enter play mode we’ll notice that collisions between the enemies and the player don’t work, only the ones of lasers and enemies as they are primitive 3D objects.
Now, we need to upgrade the enemy prefab to the new asset. Another way to do it is to enter the prefab view in the scene view by clicking the next button:
Once in there, we need to remove the components that are of the primitive 3D cube and add a sprite renderer for the 2D model. then drag the sprite that you choose into the sprite renderer and resize the gameobject as you wish:
Now the prefab view displays the new enemy model:
So, now we need to add a rigidbody 2D and a box collider 2D component to the enemy prefab. This allows the sprites to respond to collisions with other sprites.
Note: don’t forget to enable the isTrigger option of the box collider 2D and set the gravity of the rigidbody 2D to 0 as we control the enemy behavior in the script.
Also, we need to edit the collider of the gameobject so that it doesn’t cover too much extra space when the collisions are triggered:
Then, we need to add a box collider 2D to the player gameobject and edit it so that it only covers the spaceship:
Then, in order to detect the collisions properly, we need to go to the OnTriggerEnter function and add the corresponding reference to the new 2D colliders:
Once we return to Unity we’ll see that the game is working again:
Now we can detect collisions between enemies and the player, but we need to do the same upgrade (of the enemy prefab) to the laser prefab to finish with the asset upgrade. Don’t forget to enable the isTrigger option of the box collider 2D.
And once it’s done, the game will look a lot better than before when we only had primitive 3D objects in the scene:
And that’s it, you can take a prototype to the next level! :D. I’ll see you in the next post, where I’ll be showing the benefits of doing prototypes without assets in Unity.