Adding Art Assets: From Prototype to Work of Art

Joe

--

Now that the prototype of the game has the base functionality built. Lets add a bit of visual candy to the game by adding the art assets for our prototyped objects. At the same time we will switch our components from 3d to 2d, which is what we are looking for in this game.

We will start by adding a space themed background.

Background Sprite

After adding the background sprite stretch it out using the rect tool in unity so that it fills the camera view. This will ensure your full play area gets the space theme that is desired.

Next lets add a sorting layer and call it Background and the assign the sorting layer to our Background Sprite. At the same time name the background Sprite something meaningful, if not already. I just called mine SpaceBackground.

Add sorting layer and apply to background

Now test it out and see how it looks.

Prototypes with space background

Next lets work on the player. Add the Player sprite to the game

Player Sprite

Change the size of the Sprite so it fits the play area. Create another sorting layer and call it PlayArea and assign the player to that layer. Rename the Sprite to Player and set the tag to Player.

A very important step is to add the Player Script and ensure to make any changes that were made in the inspector and not in the actual script. Lastly I added a Polygon Collider 2D rather than a box collider just so it matches the shape of the ship more accurately. Don’t forget to set the collider to Is Trigger.

Add Polygon Collider 2D and set Is Trigger to true
Green outline shows the collider area

There is more work to do to get the collisions working but a quick test shows it is coming together well.

Quick play test after adding the Player sprite

Next lets fix up the Enemy Sprite. Following what was done for the Player, add the sprite and change the size to what is suitable. Add the Enemy to the PlayArea sorting layer. Change the Sprites name to Enemy as well as its tag.

Add the Polygon Collider 2D and set Is Trigger true. To get collisions to work we need a Rigidbody component, and that was on the enemy in the prototype. So lets go ahead and add a RigidBody2D component to the enemy and then set the Gravity Scale to 0.

Add the Rigidbody 2D component and set Gravity Scale to 0

Next add the Enemy Script. Before this will work though the code needs to be modified. The prototype was written in 3d and now the real assets are 2d so there are a couple of things to change in the Enemy Script in regards to collisions.

Go to the OnTriggerEnter() Method

This is the Method to Change

Then modify it for 2D like so

OnTriggerEnter() modified to work in 2D

The last thing, in my code I had some special variables to move my rotated cube straight. I no longer need those and they need to be removed so that the 2D Enemy flies properly now.

Delete the old enemy prefab and make this new Enemy prefab. Then link it to the Spawn Manager so that it knows to call this new prefab.

A quick play test shows everything is coming along nicely.

Added and modified Enemies with sprites and 2D behavior

The last step to convert over the prototype is to change the laser. Again following the same steps as previous lets add the laser sprite. Change the size to something suitable. Rename the laser sprite to Laser and set the tag to Laser. Set the sorting layer to Play Area. Add a Box Collider2D and set Is Trigger to true. Adjust the box collider so that it conforms to the size of the laser. Add a Rigidbody2D and set Gravity Scale to 0. Attach the laser script.

Delete the old 3D laser Prefab and save the new 2D laser Prefab. Click on the Player and connect the new 2D laser prefab to the player script. Last find out the offset for the laser to fire nicely from the new player sprite and adjust the offset in the Player script FireLaser() method.

A Play test should have the game working like it was previously but with the new 2D assets.

Game Updated and working with 2D art assets

--

--