Game Development Reference
In-Depth Information
What is the advantage of using enum in Unity? If we take a look at our code at the line
private var e_page : Page = Page.GAMEOVER; and change the word private
to public , then go back to the Unity and click on the HiScore game object to see the
Inspector view, we will see the new editable parameter names E_page , which is the drop-
down buton. If we click on it, we will see that we can choose only three values, which are
GAMEOVER , LOCALSCORE , and SERVERSCORE :
Those names are from the enum objects that we assigned in the HiScore.js script. The
advantage of using enum parameter is that we will be able to create the editable value that
limits the number of choices and protects an invalid input data, which will save us from
having to write an extra code to check for the invalid input data. For example, if we were
using integers, having a page value of 500—which is an invalid page number—would not
make any sense.
This is very useful when we work with other people or when we are tesing the game
because we can make it readable for everyone; they can just basically set up the enum
parameter and then adjust it in the editor while they are tesing the game.
Saving and loading the local high
score
In this secion, we will be creaing two scripts for saving and loading the high score from
our local machine. The first script will be the UsersData script, which will contain all the
funcions to save and load the score to our local machine by using the PlayerPrefs class.
Then, we will create the LocalHiScore script, which will contain the funcion to sort user
scores and check for the final score submission. Finally, we will go back to the HiScore
script to create a LocalHiscore object to save and load high scores locally.
 
Search WWH ::




Custom Search