Game Development Reference
In-Depth Information
From the preceding funcion, irst we create the
int
variable
j
, and then we use
System.
Int32.TryParse(s, out j);
to convert the string to an integer. This funcion will return
the result
true
or
false
; if
true
, it means that the result got converted to an integer, and
then we return
j
, which is the output from the
System.Int32.TryParse(s, out j);
funcion. On the other hand, if the result is not an integer, we trace out the error and
return
0
.
The
out
keyword in C# will cause the arguments to be passed by
reference, which means that we can use the
out
keyword to return
the values in the same variable as a parameter of the method.
For example, if we created the C# script named
Test
, as shown in the following script, and
atach this script to the game object in Unity, we will see the trace result display
i = 5
and
j = 0
:
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour {
// Use this for initialization
public void Start() {
int i;
int j = Testout(out i);
Debug.Log("i = " + i); //Will show the result i = 5
Debug.Log("j = " + j); //Will show the result j = 0
}
public int Testout(out int i) {
i = 5;
return 0;
}
}
Then, the rest of the
XMLParser
script is to get the value for the length of user, the
username, and score. We create this funcion because we only want to get the data from this
XML class, we don't need to set it. This is just some protecion to make sure that our user's
data that loaded from the XML doesn't change.