Game Development Reference
In-Depth Information
Before we begin to code the C#, we should know that the way to write the script in C# is
different from Unity JavaScript (we can see more details in Appendix C , Major Differences
Between C# and Unity JavaScript ), which we already know from the previous chapter.
However, we will have a quick refresh of the idea for wriing C#. First of all, when we declare
the variable in C#, we will use Type varName = value; instead of var varName :
Type = value; in Unityscript. Second, when we create the funcion in C#, the syntax
is very similar to when we create the variable. We will use something like public void
functionName () { … } instead of public function functionName () : void
{ … } that we used in Unityscript. Also, if we want the funcion to return the type, we will
just replace the word void with the type that we want. For example, if we want this funcion
to return the string type, we will write the code like public string functionName
() { … } . It's just a small switch of the syntax. Also, if we take a look at the C# syntax, we
will see that in C# we don't use the words function or var to declare either the variable or
funcion. It only uses the type to declare.
Engage Thrusters
We will double-click the XMLParser script that we just created to open it in MonoDevelop :
1. First, we will start coding at the beginning of the XMLParser script, as shown in the
following highlighted code:
using UnityEngine;
using System.Collections;
using System.Xml;
 
Search WWH ::




Custom Search