Game Development Reference
In-Depth Information
If we clicked on the
LOCAL HI-SCORE
buton, we will see that our name and score appears on
the scoreboard, as shown in the following screenshot:
Objective Complete - Mini Debriefing
We just created two classes,
UsersData
and
LocalHiScore
, for saving and loading the
user's local high score data and displayed it on the
LOCAL HI-SCORE
page by using the
PlayerPrefs
to save and load the array of
UsersData
objects. We also checked for the
user submission score and sorted the score before saving it to the local object.
In the
UsersData
script, we started by creaing the
class UsersData {
. This is because
this class only contains the data and doesn't want to use any
Start()
or
Update()
funcion
that inherits from the
MonoBehaviour
class. If we don't put the
class
keyword, Unity will
automaically inherit this class from
MonoBehaviour
, which is the default seing for Unity
Javascript
, so it means that we can run this script without adding the
class
keyword.
We can also inherit the class from
MonoBehaviour
in
Javascript
by
using the
class
keyword, as shown in the following script:
class MyClass extends MonoBehaviour { }
The preceding script will also inherit
MyClass
from
MonoBehaviour
.
However, it will be too expensive to use. To make it easy to understand,
all scripts that inherit from
MonoBehaviour
will have the
Start()
,
Update()
classes, and all the
MonoBehaviour
funcions run in the
Unity background.
The classes that aren't derived from
MonoBehaviour
objects,
Start()
,
Update()
, and so on, won't be called on
MonoBehaviour
unless they are connected to the game objects.