Game Development Reference
In-Depth Information
Once created, a new script file will be generated inside the Project folder with a
.cs file extension (representing C Sharp). The filename is especially important and
has serious implications on the validity of your script files because Unity uses the
filename to determine the name of a C# class to be created inside the file. Classes are
considered in more depth later in this chapter. In short, be sure to give your file a
unique and meaningful name.
By unique, we mean that no other script file anywhere in your project should have
the same name, whether it is located in a different folder or not. All the script files
should have a unique name across the project. The name should also be meaningful
by expressing clearly what your script intends to do. Further, there are rules of
validity governing filenames as well as class names in C#. The formal definition of
these rules can be found online at http://msdn.microsoft.com/en-us/library/
aa664670%28VS.71%29.aspx . In short, the filename should start with a letter or
underscore character only (numbers are not permitted for the first character),
and the name should include no spaces, although underscores (_) are allowed:
Name your script files in a unique way and according
to the C# class naming conventions
Unity script files can be opened and examined in any text editor or IDE, including
Visual Studio and Notepad++, but Unity provides the free and open source editor,
MonoDevelop . This software is part of the main Unity package included in the
installation and doesn't need to be downloaded separately. By double-clicking on
the script file from the Project panel, Unity will automatically open the file inside
MonoDevelop. If you later decide to, or need to, rename the script file, you also need
to rename the C# class inside the file to match the filename exactly, as shown in the
following screenshot. Failure to do so will result in invalid code and compilation
errors or problems when attaching the script file to your objects.
 
Search WWH ::




Custom Search