Diamond in the rough — A quick tip on prototyping in Unity

If you look back at my previous articles they are all using primitives as game objects.

In this article, we are going to transform our 3D prototype project into the beginnings of a 2D space game.

The first step is to find some sprites you want to represent your objects (player, enemy, laser), there are a lot of websites that offer free and paid assets for you to import into your project so we won’t need to discuss them here.

How to move a project from 3D to 2D?

There is not a lot of changes to be made fundamentally when it comes to components in 2D and 3D space.

The first step we will take is to change the scene mode to 2D.

How to convert a 3D object into a 2D object?

Next, we will convert our game objects into 2D objects. Earlier, you should found an image to represent the player, enemy, and laser. Ensure these images imported as sprites (2D and UI) otherwise covert them over by selecting the texture type of the image and finding that option in the drop-down menu

You have a couple of options for your conversions. One way is to remove the mesh renderer, mesh filter, and box collider and replace them all with their 2D counterparts which I will demonstrate on our enemy as it is a prefab.

Alternatively, you can just drop your sprite into the hierarchy, rename it to “player” and add a box collider 2D, your player script, and (in the case of the new input system) your input component. This method is quicker in objects that are not prefabs or references in other object scripts.

You may want to adjust your colliders and layers but this is something I will discuss in a different article. For now, just remember to turn the “Gravity Scale” to 0 on your rigid bodies.

Next, we need to convert our scripts. At the moment when checking for collisions, we are using the 3D version. We need to change these over.

As you see I also change the variable name over from “collision” to “other” so we can just cut our current code and paste it within our new function.

Now we have our end result.

Unity developer with a love of learning all things programming.