Game Development Reference
In-Depth Information
Player.transform.rotation.z.ToString();
break;
case "xScale":
node.InnerText =
Player.transform.localScale.x.ToString();
break;
case "yScale":
node.InnerText =
Player.transform.localScale.y.ToString();
break;
case "zScale":
node.InnerText =
Player.transform.localScale.z.ToString();
break;
}
}
xPlayer.Save(pFileName);
}
}
When we call this function, we first check whether there is actually a GameObject in
our
Player
variable. If there isn't, then no saving will be done. Next, we declare an
XmlNode
variable, which will be our root node from the XML document. After this,
we run a
foreach
loop that will find all of our child nodes within that root node.
To find specific nodes, we check the name property of that node, which actually is
what we typed to create that node. In the switch statement, we look for each node
that we want to save data to. For every node in XML, we set its
InnerText
value
to its associating value from our player's GameObject. The
InnerText
property of
a node is the data it holds and is what we will save to and load from.
Finally, we call the
Save
function from our
xPlayer XmlDocument
variable and
pass it to the directory and filename we set in our
pFileName
variable.