Prototype to Production in Unity
Objective:
Take our 3D prototype objects and replace them with our 2D sprite assets.
The Back Story:
If you’ve followed along with my previous articles then you know we’re at a point where the game play feels pretty good and we’re ready to replace the 3D cubes and capsules with actual game art. With spending an hour or two whipping up a prototype before you delve into multiple departments working on something that’s not got some shape to it to start with is a great way to waste time and money. Prototyping something out for pitching to the c-suite or to a client is easier to justify the time lost.
I’m no artist. Wish I was but ya gotta work with what the Good Lord gave you. For artwork I’ve got the fantastic assets from GameDevHQ.com from their Filebase product. Downloading the assets, unzipping and click and dragging the folder into my Projects window is how I imported the files. From there it’s easy to use.
Replacing Prototypes with Production Assets:
We’ve built our prototype with 3D primatives and with 3D colliders and event listeners. We need to change these out with our 2D sprites and the process couldn’t be easier. It literally takes 5 to 10 minutes. But we need to think about what all we need to change. As I mentioned we have 3D colliders for our 3D objects, we need to find the correct colliders to use and adjust for the differences. A quick search on Unity’s Docs makes things so very simple. I searched for “collision detection 2d” and the second link is for “Rigidbody 2D”. In that document on Rigidbody 2D I also found a link on “Introduction to Collision” — as Software Engineers we often times don’t know it all and that’s ok, our body of knowledge cannot be great when we’re just starting out on something. I’ve 20 years of web development, sure the basics of programming are easier for me to handle with the syntax of C# but my knowledge on Unity is just the same as anyone else starting out — nearly zero. But the skill of Software Engineers is to learn how to learn and how to solve a problem. My problem is I need to know what the differences are between 3D and 2D GameObjects
and their Components. The above documentation on an “Introduction to Collision” gave me the knowledge on what settings I needed for my prototype Collider components — namely using “Is Event” being checked vs not being checked. I wanted to “raise and event” so my behavior code could handle the logic on when things crash. If I were making a “Breakout” style game, I’d probably not check that box so the ball can bounce off the tiles.
So, we know from the documentation that we’re going to need to change the components for our 2D assets. I’ll start with the Laser
first. We’ll drag the laser sprite into the Hierarchy window, rename it, tag it and setup the Box Collider 2D and Rigidbody 2D — we actually don’t need the Rigidbody 2D and you’ll see me add that in the clip below, but the only GameObject
that requires the Rigidbody 2D component is the Enemy
prefab. This will save a little on the Game Engine and makes no real impact on this tiny game, but in a large game — dot your “i”’s and cross those “T”’s.
Setting up the Enemy
and the Player
are pretty much the same, we drag the asset from the Project window and drop in the Hierarchy window, resize, re-tag, set the proper sorting layer, attach our behavior scripts and copy values from the prototype and paste into the new 2D GameObject
replacements.
Next up is changing the Enemy
behavior code because as we learned from the documentation we can’t listen to OnTiggerEnter
for 2D objects, we need to change to things in our code:
That’s it! Hard right? All of the rest of the code doesn’t need to be touched.
And this is it for this article. We’ve replaced all of our 3D prototype objects with the 2D artwork, made the necessary tweaks to components, updated Prefabs and made the single line of code change necessary to get the game back to lasers firing, enemies being destroyed and player’s lives being removed when the enemy collides. Up next will be how to implement the Power-ups in the game.