Setting up your game’s basic mechanics is undoubtedly the essential step in the creation of your game. But once that is done, you want to give your game some feeling of uniqueness and its own identity. Unity3D is very good for prototyping, but once you are beyond that phase, it is now time to start creating your game with graphics, sounds, and visuals! Getting all of this done is one more step closer to finishing your game.
We will be doing a transition from 3D into 2D today. Luckily we already have a premade asset set from friends from GameDevHQ. If you do not, you can always create your own - which does take a lot of time. Alternatively, you can check out Unity’s Asset Store or scout out the web to find some free or paid ones you like.
Before we start, make sure to toggle the ‘2D’ option in your ‘Scene’ view.
Also, to keep the ‘Hierarchy clean, I will be creating an empty GameObject called ‘Environment.’ To which I will be adding the Background Sprite. After that, I will rename it and stretch it to match our ‘Game’ view.
Next up, since we are using 2D Sprites, we need to convert our GameObjects from 3D to 2D. We do this by changing our Components from 3D to 2D ones.
We do this by eliminating all of the ‘Cube (Mesh Filter)’ and ‘Mesh Renderer’ components from our GameObjects.
We also have to convert our ‘Colliders’ and ‘Rigidbodies’ from regular ones to 2D ones. Rigidbody > Rigidbody 2D & BoxCollider > BoxCollider2D. Make sure to keep these components' values and properties the same as previous ones.
Now, if we were to run our game right now, it would be broken - and the reason behind that is because our code still works with the 3D Colliders, which we need to change as well - for that, we open our ‘Enemy’ script.
Here, we need to add a ‘2D’ to our ‘OnTriggerEnter’ method name and the ‘Collider’ parameter.
Now, all we need to do is change the Sprites of our Prefabs. Do this by simply adding a ‘Sprite Renderer’ component to our Prefabs and find the sprite of the player, and set it. Also, while here, you can adjust our Player's size in the ‘Transform’ component.
Also, one thing to note, don’t forget to adjust our Players & prefab sorting layer to ‘Foreground’ and the background to ‘Background.’ This is because the GameObjects might overlap with each other.
And that is all done! Now we have our one-sided shooting range done in a brand new outfit!
But that is it for now, thank you for reading and feel free to follow me for more articles - and as always, good luck and see you next time!