Game Development Reference
In-Depth Information
node.InnerText =
Enemies[e].transform.localScale.z.ToString();
break;
}
eRoot.AppendChild(eBase);
}
xEnemy.AppendChild(eRoot);
}
}
xEnemy.Save(eFileName);
}
In the first line, we call the RemoveAll function from the xEnemy XmlDocument
variable. This deletes all of the nodes from the XML document. We do this for simpli-
city's sake, this allows us to avoid the hassle of searching for specific enemy nodes
to save data from a specific enemy. Next, we create a couple of variables. The first
one will be our root node that holds all of our enemies. The next one is a string array,
which will hold the names of nodes we will use later on.
The next step in this function is to use a for loop to iterate through our enemies'
GameObject array; this is to check whether we actually have an enemy GameOb-
ject in our array. If it runs into a null, it won't save any data for that spot.
Once we check to see that we don't have a null GameObject, we start creating our
XML data. First, we create a new XmlNode variable, which will be the root node for
our enemy data. Next, we run a for loop to create new nodes for each of the vari-
ables that we want to save. We do this by creating a new node and setting its name
to one of the strings in our nodes string array. Finally, we append it as a child to our
enemy root node.
Now that we have created the enemy node and added all of the child nodes that we
want to save to, let's iterate through those nodes and start saving our data. To check
each node, we create a foreach loop like we did to save the player data and check
the names for each of the eBase child nodes.
Search WWH ::




Custom Search