Converting from 3D to 2D in Unity
We’ll be converting the 3D greybox primitives such as cubes into 2D sprite assets in this article.
I’ll be using assets from https://gamedevhq.com/ , but you can use whatever sprites you like.
There are plenty to choose from on the Unity asset store, many of which are free!
Essentially we want to replace or modify our player, enemy, and laser prefabs as shown below:
On all of our RigidBody 2D components, we want to make sure Gravity scale is set to 0 so that the Unity physics system does not add speed to our game objects.
We’ve also added a background:
Move and resize your background sprite or image as necessary to make sure it covers the entirety of game screen.
We add 2 layers to Unity’s “Sorting Layers” in the Tags and Layers window.
It’s important to note that the order in which we add them matters.
Layers towards the bottom of the list will always show on top of layers above them on the list.
We set our enemy, laser, and player prefabs to the sorting layer of “foreground”.
Naturally, we set the sorting lay on the background to background.
Lastly, there is one bit of code we need to modify on our enemy script.
Instead of “OnTriggerEnter(Collider other)” we replace this with “OntriggerEnter2D(Collider2D other)”.
Since our prefabs have become 2D game objects with 2D collider triggers, our code has to match.
Our 3D to 2D conversion is complete!
Next time we’ll look into adding special abilities or powerups for our game!