Posts Tagged ‘C Sharp’

These posts contain C# code or are somehow related to C#.

Unity: How to make an overview map

Click here to read Unity: How to make an overview map

This Unity tutorial explains the required steps to create a map that displays the level in a top-down view. For a real-time, precise map, an orthographic camera can be placed on the top of the map and set to exclusively render a specific layer. However, this post isn’t about creating a precise map, instead it shows how to create a stylized one. A Unity project with everything explained here is available for download at the end of this tutorial.

The first step is to create a plane by clicking on GameObject->Create Other->Plane. Resize it underneath your level, making it have the same size of your scene, not bigger or smaller, just enough to fit all of the elements inside it. (more…)

Unity: How to create a GUI Sprite Sheet – Part 3

Click here to read Unity: How to create a GUI Sprite Sheet – Part 3

The final part of a series that explains how to create a GUI Sprite Sheet in Unity. This post will focus on explaining how the code works. For those who haven’t read the first and second parts, please do before going any further. As most post series in this website, there is a download with everything that had been explained at the end of the post.

With all images and the GUI Skin already set at the Unity Editor, now we just need some code to render the GUI on the screen. The following script correctly renders separately each element from the sprite sheet, and it’s attached to the Main Camera:

(more…)

Using static variables in Unity3D

Click here to read Using static variables in Unity3D

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?

(more…)

Unity3D: Creating a GUI with both 3D and 2D elements

Click here to read Unity3D: Creating a GUI with both 3D and 2D elements

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.

(more…)

Using C# delegates in Unity3D scripts

Click here to read Using C# delegates in Unity3D scripts

When Unity3D 3.0 came out, it not only fixed a lot of bugs and added features, but it also upgraded the Mono version being used, including C# language features like namespace support, linq and delegates. This post is going to be about the latter, explaining what is a delegate and what benefits it could bring when using it to develop games on Unity3D.

Basically, in C#, a delegate is a reference to a method or to a group of methods that have the same signature (returns the same type and has the same parameters). A better explanation can be found at Microsoft’s MSDN C# documentation: (more…)