From Prototype to Work of Art- Game Dev Series 13
Objective: Update the gameobjects from prototype models to assets pack.
Previous: Tidy Up the Spawning
After we completed all the basic function to our game, time to make our project looks more like a game.
I’m going to use 2D Galaxy Assets from GameDevHQ for my project. After imported the package, we can first upgrade our background.
We can simply drag our background sprite into hierarchy.
Then we can adjust the size with Rect Tool with hotkey “T”, and rename it to “Background”.
Next, let’s upgrade our Player.
Due to the Player is not a prefab, it might be easier if we create a new gameobject from sprite. Select the Player sprite from assets folder, and also drag into hierarchy.
Because our game is a 2D shooting game. All the 3D components would no longer needed. We can simply copy the script- which is the key component to our Player- to our Player sprite. Then delete the old object and rename the new one.
Then scale the size to 0.5 on X, Y, and Z. You can try to grab the gameobject and move around. You might notice that our Player would go behind the background, which is definitely not we want.
In 2D games, all the sprites are presenting as layers, which the order is important. Go to the Inspector window of Background, insides the Sprite Renderer there is a Additional Settings drop down menu. There are 2 option: Sorting Layer & Order in Layer.
We can simply change the order of it. Or we can set genre for our layers.
Click the drop down menu of Sorting Layer, and click Add Sorting Layer.
Let’s create 2 layer, Background & Foreground. Which at the top is the one far from camera.
Then assign Background layer to Background, Foreground to Player.
Now our Player should be in front of Background.
Then we should add a Box Collider 2D and a Rigidbody 2D to our Player. Check Is Trigger inside the collider, and change the Gravity Scale inside rigidbody to 0.
Next is the enemy. Enemy got a prefab so we can open prefab to adjust.
We can remove all the 3D component: Cube(Mesh Filter), Mesh Renderer, Box Collider, and Rigidbody.
Then create a 2D component: Sprite Renderer.
The we can use the enemy sprite from assets to the renderer.
Then set the layer to Foreground, and add a Box Collider 2D and Rigidbody 2D.
Because all the collision is using the enemy script, we need to change it works in 2D.
We used OnTriggerEnter in 3D environment, now it should be OnTriggerEnter2D. And also the Collider should be Collider2D.
The last is the laser. Although laser got a prefab, since we are going to make a 2D gameobject, it might be easier if we make a new prefab to it.
Drag the sprite of laser into hierarchy, and also add a Box Collider 2D and Rigidbody 2D to it.
Add Laser script to it, scale to 0.2 on all the axis, and scale the collider.
Replace the Laser prefab and reassign it to player script.
Don’t forget to select the tag to all the gameobjects.
Then we can Play it to check the result!