Game Development Reference
In-Depth Information
}
// C# user:
…
UserData _user;
LocalHiscore _localHiscore;
Vector2 _scrollLocal = Vector2.zero;
…
void Awake () {
_localHiscore = GetComponent<LocalHiscore>();
if (_localHiscore == null) {
_localHiscore =
gameObject.AddComponent<LocalHiscore>();
}
}
void Start () {
…
_localHiscore.Initialize(maxUser);
}
5. Next, we will go to the
Gameover()
function to add the load and save data
functions when the user clicks the button, as shown in the following highlighted
code:
// Unity JavaScript user:
…
private function Gameover ()
{
…
if (_clickSubmit == false) {
…
if (GUI.Button(_buttonRect1, "SUBMIT")) {
…
_user.score = HitPoint.CURRENT_SCORE;
_localHiscore.SaveUserData(_user);
}
}
if (GUI.Button(_buttonRect2, "LOCAL HI-SCORE")) {