MonoDevelop Basics

In this article, you will build a C# script from scratch and learn the most important tools in MonoDevelop.

Code completion

Also referred to as autocomplete or IntelliSense, code completion describes the greatest tool every created for programmers. By its name you alreasy know what it does, but we’ll go over the details soon.

First, open a Unity project and create a new C# script called Player. Next, open it in MonoDevelop by double clicking it and delete everything inside it. Now, let’s start from scratch:

This is all you need to define a class in C#. But before you start typing, follow these guidelines:

MonoDevelop code-completion.
MonoDevelop code-completion.

Type the first two letters of the word public and hit Enter to auto-complete it. From now on, there will be almost nothing that you have to type out in its full length. If auto-completion doesn’t pop up you can force it via a keyboard shortcut; in my case: CTRL + Space.

If you’re having trouble, check your preferences:

MonoDevelop code completion preferences.
MonoDevelop code completion preferences.


Continue to define your class by typing the letter and hitting Enter to autocomplete it to class. Names like Player are not (yet) in your auto complete list, so you’ll have to spell it out. But once you’re done with your class definition, you will also have access to Player in your code completion window.

In fact, auto completion is a list of all keywords that are currently available to you. This includes keywords from the C# language itself, such as public or class, as well as classes or variables, which you defined.

Next, we want our script to derive from the MonoBehaviour class, because this is what we need to make our script work as a component on a GameObject in Unity. If you try to type out the keyword, there won’t be any auto complete suggestions at the moment. This is, because MonoDevelop doesn’t know about Unity’s MonoBehaviour at the moment. Let’s tell it:

Remember to only type the first few letters and then autocomplete with Enter.

UnityEngine is a collection of classes. MonoBehaviour is one of the classes that live within the UnityEngine namespace. Now, we can use auto completion to inherit from MonoBehaviour and give our class access to all the Unity goodies.

Now we have a functioning class. Save your file and check for errors in Unity, by attaching your script to a GameObject in the scene and hitting Play. Open the console window to see, if any errors appear in the log.

Continue with the following example:

For testing purposes, we will define another class within the same C# script. In fact, this is not a unusual thing to do, just be aware of the fact, that only the first class in a file can be a MonoBehaviour. Following MonoBehaviours will just not work correctly, although no error is shown in Unity.

Construct a new instance of the Test class in the Start() method and store a reference to it in a variable called test of the Type Test.

If this does not yet make sense, don’t worry, just copy the code and follow along to learn more about auto completion.

Code completion showing class members.
Code completion showing class members.


Now that we a class instance called test, we can use the dot-operator to access members (public variables) of that class.

Use auto completion to find your variables.

A short rundown of icons used in MonoDevelop’s auto completion:

  • M : method (function)
  • P : property
  • F : field (member variable)
  • C : class

(There are a few more icons, but I’ll save them for later.)

Here is our complete script with a print statement to see if it works correctly:

Checking variable values via the print statement is rather tedious and not very elegant. Click here to learn how to make private variable visible in the inspector.

Renaming variables and classes

If you ever want to rename a variable, be sure to use MonoDevelop’s renaming tool: Select your variable (highlight it or just place your cursor within it) and hit CMD/CTRL + R or right click Refactor Rename. This process is called refactoring because we don’t just want to rename a single word, but instead rename all instances of our variable.

Refactoring a class works the same way, but be aware that a class that derives from MonoBehaviour must have the same name as the file that is attached to a GameObject in the scene.


Line endings

Published by

Chris Yarbrough

Game Design student at Mediadesign Hochschule, Munich.

Leave a Reply