Game Development Reference
In-Depth Information
Engage thrusters
Now, we can start creating the
XMLParser
script using the following steps:
1. We will navigate to
Chapter8
|
Scripts
|
C#
|
Hiscore
(for C# users) or
Chapter8
|
Scripts
|
Javascript
|
Hiscore
(for Unity JavaScript users), and right-click and go
to
Create
|
C# Script
(for C# users) or
Create
|
Javascript
. We will name it
XMLParser
and double-click on it to open the
XMLParser
file.
2. First, we will start coding at the beginning of the
XMLParser
script, as shown in
the following code:
// Unity JavaScript user:
#pragma strict
import System.Xml;
// C# user:
using UnityEngine;
using System.Collections;
using System.Xml;
We added
using System.Xml
, and
import System.Xml
allows us to ac-
cess the
System.Xml
library in the .NET framework.
3. Next, we will create the
XMLParser
class as the static class, which allows us to
access the method of this class directly without creating a new
XMLParser
object
and all the necessary variables. Let's add the following code:
// Unity JavaScript user:
public static class XMLParser {
private var _doc : XmlDocument;
private var _root : XmlNode;
private var _users : UserData[];
private var _userLength : int;
public function get users() : UserData[] {
return _users;