Game Development Reference
In-Depth Information
Classified Intel
In this secion, we have used the PlayerPrefs to load and save the user data (name and
score) to our local machine. The PlayerPrefs class is basically used for saving or loading
the data by using the key string to idenify each piece of data. We can set the value that we
want to store and load to string , float , or int type.
For storing or saving the data, we can use PlayerPrefs.SetInt(Key, Value) ,
PlayerPrefs.SetFloat(Key, Value) , or PlayerPrefs.SetString(Key, Value) .
We can create the new data by giving a different Key for each saving data. On the other
hand, if we want to replace the old data with the new data, we just have to set the same Key
to the new data that we will save.
For loading the data, we will use PlayerPrefs.GetInt(Key) , PlayerPrefs.
GetFloat(Key) , or PlayerPrefs.GetString(Key) to get value that we have stored.
We can also check whether the data is already stored in this machine or not by using
PlayerPrefs.HasKey(Key) .
We already talked about how to save and load the data from PlayerPref , but we didn't
talk about how to remove it. We can use PlayerPrefs.Delete(Key) to remove the data
that we don't want by specifying the Key . Also, if we want to remove all the data that we
have saved, we can use PlayerPrefs.DeleteAll() .
We can also go to the following website for more details on the
PlayerPrefs class:
http://unity3d.com/support/documentation/
ScriptReference/PlayerPrefs.html .
Getting XML data from the server
In this secion, we will create the C# script that will parse the XML data from the server
to use in the next step. We will create the C# script because it is much easier to use the
XmlDocument from .Net framework in C#.
Prepare for Lift Off
Let's go to Assets | Create | C Sharp Script and name it XMLParser and put it inside the
Standard Assets folder, as shown in the following screenshot:
 
Search WWH ::




Custom Search