We are now in the last stage of our prototype. The base features all seem to work, so now, we can start adding the artwork to get a better idea of how the final product is going to look. This involves two things: Converting all the game objects from 3D to 2D, and loading up all the art.
The first, we could have perhaps avoided by making a better decision when we first fired up the project and selected 3D. Be, that as it may, it’s really not that big a deal to switch things over. There are two ways to do this. The first is to simply delete the 3D game object and recreate it from scratch using a 2D asset. The second is to simply remove the 3D components and add the 2D components back in and reconfiguring.
The first thing you want to do is change the Scene view from 3D to 2D using the toggle in the upper left of the Scene window.
For my game I converted one 3D object to a 2D object, and another I recreated from scratch. Honestly, I did not see much difference in level of effort other than recreating one from scratch gave a slightly higher chance of forgetting a configuration. So, making a quick checklist is not a bad idea.
- The items needing converted are the Player, Enemy prefab and Laser prefab
- Remove the Cube (Mesh Filter) component
- Remove the Mesh Renderer component
- a Sprite Renderer component needs to be added
- Drag the chosen sprite into Sprite field of the Sprite Renderer component
- The [3D] Box Collider component needs replaced with the 2D version, “Box Collider 2D”. All three objects will need a Collider
- Select the “Is Trigger” checkbox of the 2D Box Collider
- Replace the 3D Rigidbody component with the 2D version, “Rigidbody 2D”. In my current configuration, only the Enemy game object requires this
- Set the Gravity Scale field in the Rigidbody 2D to zero
- Be sure to set the tag to either Enemy, Laser or Player as needed
- Add the appropriate behavior Script
- Create a ‘Background’ and ‘Foreground’ sorting layer. Be sure ‘Background’ is listed first
- In the Additional Settings of the Sprite Renderer component, set the Enemy, Laser and Player game objects/prefabs to ‘Foreground’
- Set background image sorting layer to ‘Background’
- In the scripts for all three, the
OnTriggerEnter(Collider other) { }
method must be changed to the 2D versionOnTriggerEnter2D(Collider2D other) { }
- Be sure that all scripts requiring a game object have that game object dragged into the Inspector
As you can see, it’s not very complicated, but there are quite a few things that could be missed. But once it is done, we have a much-improved prototype.
As one final note, I mentioned in a previous post that when I first went to Window -> Package Manager -> Built-in Packages, everything was disabled. In order to do my previous work, I had to enable the [3D] Physics package. I had pre-emptively enabled the Audio package. When I tried to add the 2D components, they were not listed in the add components dialog. That’s when I remembered this and realized I needed to enable the Physics 2D package. On a lark, I went ahead and disabled the standard 3D Physics package, and everything seemed to still work.