Unity

In my last post, I talked about MonoGame and I had several other MonoGame subjects lined up. The next subject was going to be the use of shaders. There are a few articles on XNA Pixel shaders and vertex shaders that are pretty good. Unfortunately, they were written for versions of XNA before version 4 and MonoGame is based on XNA version 4. I spent quite a bit of time converting from the version they were written in to get them to work in MonoGame. After many fruitless hours of trying to convert code that was incomplete (some sites had downloadable content that no longer existed) and guessing at what the old programmers were trying to do, I threw in the towel.

My next task was to research a new game development environment and it looks as if there are two: Unity and Unreal Engine 4. The Unreal engine is very high-end and requires the use of C++. Both Unreal and Unity use a design pattern where the environment is a graphic/physics engine that you add code to manipulate. In the past a game developer would use a language and add modules to the environment to perform graphic functions. As you can tell by the title of this blog post, I’m not going to cover Unreal in this post (maybe a later post). If you decide to install Unreal, be prepared to spend hours downloading and installing the application. This is a high-end product and there are a lot of materials, sounds, templates, and samples. The entire installation is almost 20 gigabytes in size. If you’re serious about game development, and you are adept at c++, I would encourage you to dive in and give Unreal a try.

Unity is very similar in layout. After installing Unity, I would recommend doing at least one tutorial. The environment is a steep learning curve, so prepare to focus on simple tasks before you decide to dive in and create your game. The first tutorials for unity guide you through a game that has pre-fabricated objects. You learn how to set trigger points and set the physics properties of objects (so they have mass and fall when released). Once you’ve tried out the entry tutorial, I would recommend this site: (cat like coding) C# and Shader Tutorials. The first tutorial called “Game Objects and Scripts” shows how to build a working 3D clock using objects that are built into Unity.

Game Objects and Scripts

This will get you familiar with using Visual Studio and Unity. A word of warning: Visual Studio does not perform the compile for unity. Unity has a C# compiler built-in and it is not 100% compatible with Visual Studio. If you use an advanced Visual Studio feature, it will not compile in Unity. Just keep that in mind if you run into a compiler error that doesn’t show up in Visual Studio.

The tutorial site contains a lot of tutorials on every subject needed to get a game rolling. The strategy game hex map examples is impressive.

Hex map path finding tutorial

There is also a maze game that is similar to Castle Wolfenstien. This is a 3D maze that is randomly generated. The tutorial shows how to eliminate walls to form larger rooms and how to add doors to close rooms. Here’s an example maze from the tutorial:

Sample maze from tutorial

Here’s the player camera view:

Player camera view

If you’re planning to design and build a shooter game, this could be a good place to start. By studying the code used to create this environment, you’ll get intimately familiar with how Unity works with C#.

Using Unity with Blender

If you’ve never used Unity before, you’ll fall into the same trap I did. Unity has a set of basic 3D objects that you can choose from the menu. You can easily add texture to the objects and manipulate them with C# (you’ll learn that when you do the clock tutorial). When you attempt to create a game of your own design, you’ll discover that you can’t create custom shapes. For that, you can use Blender and import the shape into Unity.
I created a space capsule in Blender and imported into Unity. After importing the mesh, I applied a texture to the shape in Unity. To create a capsule, open Blender and delete the cube.

  1. Add a new cone object.
  2. Set the base to 2.0 (radius 1).
  3. Press the tab button to enter edit mode.
  4. Right-click the top vertex to select it.
  5. Use the vertex level (Shift-Ctrl-B)
  6. Move your mouse up and down to cut off as much as you’d like, then click the mouse button to complete the operation.

You can add a squat cylinder around the base to make it look more like a space capsule, but I’m just going to demonstrate how to get this shape into Unity. You can get other ideas from this stack exchange post (which is where I obtained the above information): Slice the top of a cone.

Next, you’ll want to delete the camera and light source. Just select them from the scene and hit the delete button (and enter).

Selecting the lamp object

Save your work. Open Unity and create a new project. Then drop your saved blender file into the “Assets” folder of your unity project. I created a Unity project named “Space Capsule”:

Blender file copied into Assets folder of Unity project

Inside your Unity project, you’ll see the object:

simple capsule asset inside Unity

Drag your capsule to the upper left view window to create an instance:

You can treat the capsule just like any other object used in the Unity tutorials.

Leave a Reply