Posts Tagged ‘Programming’
Programming related posts.
Using static variables in Unity3D
Posted by Dimitri | Filed under Programming
This post explains how to use static variables when programming scripts for the Unity3D engine. The example scripts in this post are written in C#, but the same guidelines apply for JavaScript.
Before delving deeper into the subject, it goes without saying that static variables should be avoided at all costs, for a great number of reasons that can be easily be found on the internet. It’s better to use a Singleton creational pattern in most cases. with that in mind, here’s a short definition of static variables: they are variables that belong to a class, and not the objects the class creates. This means that static variables retain the same value, regardless of the object from a given class. Another characteristic is that, as long as the class is in the memory, they are still valid references. Static variables are initialized by the compiler right before the class creation, and before any other variables or methods. But what does it mean for Unity3D scripts?
Configuring openFrameworks add-ons in Codeblocks
Posted by Dimitri | Filed under Programming
At some point, when using openFrameworks to create interactive applications, one needs to use some of the bundled add-ons. This post will explain how to configure your Codeblocks project to use these add-ons and how to include the OpenCV add-on to your project. Before continuing, you should know there is an automated tool that helps the programmer in this process, specially designed to easily configure openFrameworks projects and add-ons at Google Code: ofcodeblocksplugin (official forum thread here).
Differently from this tool, this post explains on how to manually include the add-ons to your openFrameworks project. The process described here was done using Codeblocks 10.05 and openFrameworks 0.62 on a computer running Windows.
Unity3D: Creating a GUI with both 3D and 2D elements
Posted by Dimitri | Filed under Programming
This post explains how to create a GUI on the Unity3D game engine that has both 2D and 3D elements in it. Some may say that is just a matter of setting up a new camera with a dedicated culling mask just to render the 3D elements on the GUI. While this is partially true, adding a 2D image using a script with GUI function calls will cause the 3D image to be covered by the 2D image. That’s why this post will focus on how to set a GUI that has a 3D element with a 2D background.
As usual, at the end of the post, a Unity3D project is available for download with everything that was explained here.
Game Programming Basics: Creating a FPS counter
Posted by Dimitri | Filed under Programming
Sometimes, while creating a game, a programmer realizes that he/she needs to make sure if some part of the code is running fast enough, before adding more things that could cause the game to slowdown. To properly measure a game’s performance, there is the need to program a FPS (frames per second) counter. As the name suggests, it will count the number of frames that where rendered at the period of one second.
This is an essential information when creating games, as it will serve as a strong indicator to measure the performance impact of a recently added element to the game.
Unity3D: Programming a machine gun – Part 2
Posted by Dimitri | Filed under Featured, Programming
This is the second and last post of this series that explains how to code a machine gun in Unity3D. The first post explained how to make the automatic firing mechanism, and this one will focus on how to set-up the machine gun, the bullet and explain the code that makes it all work. Also, a Unity3D project with all the source code discussed on the series is available for download at the end of the post.
So, let’s start by setting the machine gun. The 3D model of the gun can be any one, you don’t even have to create a 3D model at all, it is possible to use Unity3D’s cubes and other primitives. The only thing that one must know is that the muzzle of the gun must be a completely separate element. This is crucial when making the gun at an external 3D modeling application such as 3D Studio Max, Blender or XSI. (more…)