A short note on using Object Oriented models in Unity

In the last weeks as a part of my learning Unity development I have been exploring how to integrate object oriented programming (OOP) modeling concepts in Unity, as done in projects such as in those by Brett Hewitt, Unity 4.x Game AI Programming,  in the Unity examples and in others created by friends. Given what a nice and evolved language is C#, the temptation of projecting the OOP techniques I’m used to in Java is irresistible.

One useful answer to a “root” doubt I got it here:

OOP for Unity

But my impression was more and more that I simply had to drop my “start modeling from the root” approach (coming from server side web development) as wrong, and now the point has become clear: in Unity you simply don’t begin at the top of the object hierarchy, not even closer: you begin at the bottom! MonoBehaviour is neither an interface nor an abstract class, but as concrete as it can be, handling e.g two timelines and a series of extension by components. The correct way is to use a component based approach, just like MonoBehaviour does, where your MonoBehaviour (flat, direct, and final) extensions instances can carry modeling properties which can use inheritance modeling.

Happier now Sorriso

Social Share Toolbar

A very basic Unity 2D tutorial in C#

On YouTube there is a popular tutorial for Unity 2D game development for beginners, in 18 videos, starting here:

Unity 2d game tutorial–part 1 of 18

where you create a Galaga-like game.

The code in the videos is in JavaScript, I followed the tutorial re-writing all code in C#. Note: I am not the author of the YouTube tutorial.
It was quite noticeable while writing code how simply using a statically typed language as C# can avoid quite a number of errors in writing the code.

You can download the complete project written in C# here:

Now some note of caution on the tutorial:

– It is not a tutorial on how to write code correctly in C#, or on how to structure object oriented programming for a game made in Unity, or on how to model AI, game mechanics and so on.

– It is not a tutorial on how to write real, commercial 2D games in Unity – more so now that Unity 4.3 is coming with a brand new integrated approach to 2D games.

The tutorial just introduces Unity as a 2d game tool and makes you use the very basic concepts. From what you learn you can use Unity to test basic game mechanics, but from this to creating professional games in Unity there is a long way to go. I’m proceeding with the books linked and with more complex projects: but thank you tutorial, it was a nice first go at it.

You can keep in contact with me on Twitter.

Social Share Toolbar