Game Development Reference
In-Depth Information
Classified Intel
At the beginning of this secion, we added the
XMLParser
script to the
Standard Assets
folder. Why did we do that? Is it really important to add the script in the
Standard Assets
folder? The answer is "Yes". We need to put this script in the
Standard Assets
folder. This
is because of the way Unity builds the script. In Unity, the JavaScript is built first and then the
C# script, so if we want to call a C# script from our JavaScript, we will get the error, as shown
in the following screenshot (you can see more details in
Appendix C
,
Major Differences
between C# and Unity JavaScript
):
So, the best way to do it is to code our enire project either in JavaScript or C#. However,
there is a way to call the C# script funcion or class from Unity JavaScript, which is the way
we just did in this chapter. As we know JavaScript is complied before the C# script. Also,
all the code or scripts in the
Standard Assets
folder will be compiled before the rest
of the code in the project is compiled. So, we just reordered the code complier to compile
XMLParser
first and then the rest of our code later.
We can read more details of the compiler order from the following
Unity website:
http://unity3d.com/support/documentation/
ScriptReference/index.Script_
compilation_28Advanced29.html
.
Posting and loading high scores to
the server
In this secion, we will create the
ServerHiScore
script to post and load the high score
data from the server, which we will use in the
WWWForm
class to communicate with the PHP
file on the website, which I already set up. We will also create a hash key and encrypt it
with the MD5 encrypion to protect and check for the user before posing the score to
the database.
Prepare for Lift Off
Before we create the
ServerHiScore
script, we will need to get the MD5 encrypion
script to encrypt our data. Let's create the new Unity JavaScript and name it
MD5.js
in
MonoDevelop
. Then, browse to the following link:
http://www.unifycommunity.com/wiki/index.php?title=MD5
.