Guest User

Untitled

a guest
Jun 24th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Xml;
  4.  
  5. public class Player : MonoBehaviour {
  6.  
  7. bool m_jump;
  8.  
  9. GakiManager gakis;
  10.  
  11. // Use this for initialization
  12. void Start () {
  13. gakis = new GakiManager();
  14. m_jump = false;
  15.  
  16. // loading of the position
  17. XmlDocument xmldoc = new XmlDocument();
  18. xmldoc.Load("save.xml");
  19. XmlNode pos = xmldoc.GetElementsByTagName("position").Item(0);
  20. string string_x = pos.Attributes.GetNamedItem("x").Value;
  21. string string_y = pos.Attributes.GetNamedItem("y").Value;
  22. string string_z = pos.Attributes.GetNamedItem("z").Value;
  23.  
  24. double x = System.Convert.ToDouble(string_x);
  25. double y = System.Convert.ToDouble(string_y);
  26. double z = System.Convert.ToDouble(string_z);
  27. Debug.Log(x+", "+y+", "+z);
  28.  
  29. //this.transform.position = new Vector3((float) x, (float) y, (float) z);
  30. }
  31.  
  32. // Update is called once per frame
  33. void Update () {
  34. gakis.Update();
  35. if (Input.GetKey(KeyCode.RightArrow)) {
  36. this.transform.Translate(new Vector3(0.1f,0,0));
  37. }
  38. if (Input.GetKey(KeyCode.LeftArrow)) {
  39. this.transform.Translate(new Vector3(-0.1f,0,0));
  40. }
  41. if (Input.GetKey(KeyCode.UpArrow) && m_jump == false) {
  42. this.rigidbody.velocity = new Vector3(0, 5, 0);
  43. m_jump = true;
  44. }
  45. if (Input.GetKey(KeyCode.Return) && m_jump == false) {
  46. Vector3 pos = this.transform.position;
  47. Debug.Log("Sauvegarde");
  48. XmlDocument xmldoc = new XmlDocument();
  49. XmlNode node = xmldoc.CreateNode(XmlNodeType.Element, "position", "");
  50.  
  51. XmlAttribute attrx = xmldoc.CreateAttribute("jia","x","");
  52. attrx.Value = pos.x.ToString();
  53. node.Attributes.Append(attrx);
  54.  
  55. XmlAttribute attry = xmldoc.CreateAttribute("jia","y","");
  56. attry.Value = pos.y.ToString();
  57. node.Attributes.Append(attry);
  58.  
  59. XmlAttribute attrz = xmldoc.CreateAttribute("jia","z","");
  60. attrz.Value = pos.z.ToString();
  61. node.Attributes.Append(attrz);
  62.  
  63. xmldoc.AppendChild(node);
  64.  
  65. xmldoc.Save("save.xml");
  66. }
  67.  
  68. if ( this.rigidbody.velocity.y == 0 ) {
  69. m_jump = false;
  70. }
  71. }
  72. }
Add Comment
Please, Sign In to add comment