Game Development Reference
In-Depth Information
public string name;
public int score;
public int CompareTo (UserData compare )
{
// Null value means that this object is greater
if (compare == null) return 1;
else {
return this.score.CompareTo(compare.score);
}
}
}
In this step in C# script, we added
[System.Serializable]
to enable the
ability to serialize the
UserData
object. This process will translate the object
data structure to a series of bits, which can easily be stored in a file or memory
buffer. On the other hand, we don't need to include any script for Unity JavaScript
because all Unity JavaScript classes are automatically serialized. This script is
used to contain the information for each user. This will be used with
Bin-
aryFormatter
and
MemoryStream
to save multiple users' data to the local
machine using
PlayerPrefs
in the
Saving and loading the local high score
section.
Tip
In C#, sometimes, we add
[System.Serializable]
in our code to embed a
class with subproperties in the inspector. This is similar to how
Vector3
looks
in the inspector. However, we don't need to add anything for Unity JavaScript be-
cause the
Serializable
attribute is implicit and not necessary.
More details can be found at
http://docs.unity3d.com/Documentation/ScriptRefer-
2. Next, we will navigate to
Chapter8
|
Scripts
|
C#
|
UI
(for C# users) or
Chapter8
|
Scripts
|
Javascript
|
UI
(for Unity JavaScript users); double-click on
UIHiscore
to open it, as shown in the following screenshot: