Game Development Reference
In-Depth Information
Unlike UnityScript or Boo, the scripting template generated with C# contains the script or class
name as part of the script itself. For that reason, you should always name the script as soon as you
create it. Also, Unity will allow you to use spaces in the name, but internally, they will be removed.
So a best practice is to use “CamelCase,” where the first letter of each word is capitalized or use
underscores. This will help prevent confusion when you have assets, scripts, and variables of the
same name by allowing you to reserve spaces for asset names.
5.
Open the new script by double-clicking on it in the Project view.
The MonoDevelop script editor opens, showing your newly created script (Figure 5-2 ).
Figure 5-2. The new script in the MonoDevelop script editor
In the regular Unity editor, the icon shows that the script is a C# script. In the script editor, you
can see by its name in the tab that the extension for a C# script is .cs . The left pane shows the
Document Outline area. This is where a list of functions and variables can be seen as long as there
are no syntax errors in your code.
In the code section, you will notice that a lot of the text is color coded. Words in blue such as
“using” and “void” are reserved words. Comments are in green and are ignored when the script is
evaluated. The first two lines tell the engine where to find most of the functions. At line 4, you will see
that in C# the class name must be explicitly declared. The name is the name of the class, the name
of the script and, once applied to a gameObject, the name of the script as a component—unlike
UnityScript, where the name of the class is assumed to be the name of the script. Inside the class
declaration, you will see the two blocked-in functions, Start and Update . Functions, as you will find
later in this chapter, are where the functionality for your game gets carried out.
The MonoDevelop editor has a lot of nice features that you will be introduced to throughout this
chapter. In case you are feeling a bit overwhelmed by all of its menus and tools, you needn't worry.
There are really only a handful that you will use on a regular basis.
 
Search WWH ::




Custom Search