Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Xml;
- public class Player : MonoBehaviour {
- bool m_jump;
- GakiManager gakis;
- // Use this for initialization
- void Start () {
- gakis = new GakiManager();
- m_jump = false;
- // loading of the position
- XmlDocument xmldoc = new XmlDocument();
- xmldoc.Load("save.xml");
- XmlNode pos = xmldoc.GetElementsByTagName("position").Item(0);
- string string_x = pos.Attributes.GetNamedItem("x").Value;
- string string_y = pos.Attributes.GetNamedItem("y").Value;
- string string_z = pos.Attributes.GetNamedItem("z").Value;
- double x = System.Convert.ToDouble(string_x);
- double y = System.Convert.ToDouble(string_y);
- double z = System.Convert.ToDouble(string_z);
- Debug.Log(x+", "+y+", "+z);
- //this.transform.position = new Vector3((float) x, (float) y, (float) z);
- }
- // Update is called once per frame
- void Update () {
- gakis.Update();
- if (Input.GetKey(KeyCode.RightArrow)) {
- this.transform.Translate(new Vector3(0.1f,0,0));
- }
- if (Input.GetKey(KeyCode.LeftArrow)) {
- this.transform.Translate(new Vector3(-0.1f,0,0));
- }
- if (Input.GetKey(KeyCode.UpArrow) && m_jump == false) {
- this.rigidbody.velocity = new Vector3(0, 5, 0);
- m_jump = true;
- }
- if (Input.GetKey(KeyCode.Return) && m_jump == false) {
- Vector3 pos = this.transform.position;
- Debug.Log("Sauvegarde");
- XmlDocument xmldoc = new XmlDocument();
- XmlNode node = xmldoc.CreateNode(XmlNodeType.Element, "position", "");
- XmlAttribute attrx = xmldoc.CreateAttribute("jia","x","");
- attrx.Value = pos.x.ToString();
- node.Attributes.Append(attrx);
- XmlAttribute attry = xmldoc.CreateAttribute("jia","y","");
- attry.Value = pos.y.ToString();
- node.Attributes.Append(attry);
- XmlAttribute attrz = xmldoc.CreateAttribute("jia","z","");
- attrz.Value = pos.z.ToString();
- node.Attributes.Append(attrz);
- xmldoc.AppendChild(node);
- xmldoc.Save("save.xml");
- }
- if ( this.rigidbody.velocity.y == 0 ) {
- m_jump = false;
- }
- }
- }
Add Comment
Please, Sign In to add comment