Game Development Reference
In-Depth Information
Saving the enemy data
We will add the function to save our enemy data. This function will look similar to our
function to save player data, except with a little more complication since we will be
intending this function to save for multiple enemies. Add this function to your script
now, just below the SavePlayer function:
void SaveEnemies()
{
xEnemy.RemoveAll();
XmlNode eRoot =
xEnemy.CreateNode(XmlNodeType.Element, "eData",
"");
string[] nodes = {"name", "xPos", "yPos",
"zPos", "xRot", "yRot", "zRot", "xScale",
"yScale", "zScale"};
for(int e = 0; e < Enemies.Length; e++)
{
if(Enemies[e] != null)
{
XmlNode eBase =
xEnemy.CreateNode(XmlNodeType.Element, "enemy",
"");
for(int n = 0; n < nodes.Length; n++)
{
XmlNode newNode =
xEnemy.CreateNode(XmlNodeType.Element,
nodes[n], "");
eBase.AppendChild(newNode);
}
foreach(XmlNode node in eBase.ChildNodes)
{
Search WWH ::




Custom Search