Game Development Reference
In-Depth Information
loaded into our player GameObject. Next, we check whether the player GameObject
isn't null as a fail-safe, then we start loading our data.
To load our data, we first create an XmlNode root from xPlayer XmlDocument .
Then, we run a foreach loop to look for every child node within the root node. We
then assign our placeholder variables we just created with the InnerText values
from each of the child nodes. Since a string can't be loaded into a float variable, we
use the Convert method to make the string into a float for the InnerText values.
Finally, after we load our data from the XML document into our placeholder variables,
we start assigning them to our player GameObject. We access the transform of the
player and assign the position, rotation, and scale to our new values.
Loading the enemy data
Now, we load our enemy data from our EnemyData XML document. This process
is similar to loading our player data, except that we will change the code slightly to
accommodate multiple GameObjects. Add the following function to your script now
just after the SaveEnemies function:
void LoadEnemies()
{
string name = "";
float xPos = 0.00f;
float yPos = 0.00f;
float zPos = 0.00f;
float xRot = 0.00f;
float yRot = 0.00f;
float zRot = 0.00f;
float xScale = 0.00f;
float yScale = 0.00f;
float zScale = 0.00f;
for(int e = 0; e < Enemies.Length; e++)
{
if(Enemies[e] != null)
{
Search WWH ::




Custom Search