private void OnGUI() { GUI.skin = MySkin; GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(Screen.width / 800.0f, Screen.height / 600.0f, 1)); GUI.Label(new Rect(0, 0, 450, 200), "Posicion: " + PosPlayer); if (GUI.Button(new Rect(0, 500, 200, 100), "Guardar")) { SysGuardar.Guardar_Posicion(PosPlayer); } if (GUI.Button(new Rect(200, 500, 200, 100), "Cargar")) { GameObject.FindGameObjectWithTag("Player").transform.position = SysGuardar.Cargar_Posicion(); } }
public void Guardar() { SysGuardar.Guardar_Posicion(PosPlayer); }
// Update is called once per frame void Update() { anim.SetFloat("Speed", Mathf.Abs(rb2d.velocity.x)); anim.SetBool("Grounded", grounded); anim.SetBool("SwordAtack", false); //anim.SetBool("AxeAtack", false); anim.SetBool("BowAtack", false); anim.SetBool("AxeAtack", false); if (Input.GetKeyDown(KeyCode.Alpha0)) { // comprovem si tenim pocions. num = System.Int32.Parse(potions.text); if (num > 0) { // la posicó fa que la barra de vida estigui al máxim. hp = maxHp; health.transform.localScale = new Vector2(hp / maxHp, 1); // so de restauració de vida. soundSource.clip = potionSound; soundSource.Play(); //restem una posió. num = num - 1; potions.text = (num).ToString(); } } if (Input.GetKeyDown(KeyCode.Alpha1)) { //swordAtack = true; anim.SetBool("SwordAtack", true); swordStatus.text = "Activat"; //anim.SetBool("SwordAtack", false); //swordAtack = false; soundSource.clip = swordSound; soundSource.Play(); } // atac amb fletxa. if (Input.GetKeyDown(KeyCode.Alpha2)) { // comprovem si teneim fletxes. arrowsCounterNum = System.Int32.Parse(arrowsCounterText.text); //comprovar si tenim fletxes if (arrowsCounterNum > 0) { // desdativem l'escut per atacar amb fletxes. anim.SetBool("ShieldAtack", false); anim.SetBool("BowAtack", true); // quaternion.eduler ens permet aplicar la rotació de la fletxa. Instantiate(arrow, transform.position, Quaternion.Euler(0, 0, arrowRotation)); // restem una fletxa. arrowsCounterNum = System.Int32.Parse(arrowsCounterText.text); arrowsCounterText.text = (--arrowsCounterNum).ToString(); soundSource.clip = shootingArrowSound; soundSource.Play(); } else { // no tenim fletxes. anim.SetBool("BowAtack", false); } } // Escut. if (Input.GetKeyDown(KeyCode.Alpha3)) { if (shieldStatus.text == "Activat") { anim.SetBool("ShieldAtack", true); anim.Play("Player_Shield"); anim.Play("Player_Shield"); anim.Play("Player_Shield"); anim.SetBool("ShieldAtack", false); } } // atac amb foc. if (Input.GetKeyDown(KeyCode.Alpha4)) { // comprovem si teneim foc. fireCounterNum = System.Int32.Parse(fireCounterText.text); //comprovar si tenim fletxes if (fireCounterNum > 0) { // desdativem l'escut per atacar amb fletxes. anim.SetBool("ShieldAtack", false); anim.SetBool("PlayerIdle", true); // quaternion.eduler ens permet aplicar la rotació del foc. //Instantiate(fireShot, transform.position, Quaternion.Euler(0, 0, arrowRotation)); Instantiate(fireShot, transform.position, Quaternion.Euler(0, 0, arrowRotation)); // restem un foc. fireCounterNum = System.Int32.Parse(fireCounterText.text); fireCounterText.text = (--fireCounterNum).ToString(); soundSource.clip = fireBall; soundSource.Play(); } else { // no tenim fletxes. anim.SetBool("BowAtack", false); } } //atack amb destral. if (Input.GetKeyDown(KeyCode.Alpha5)) { if (AxeStatus.text == "Activat") { anim.SetBool("AxeAtack", true); soundSource.clip = swordSound; soundSource.Play(); } } // saltem. if (Input.GetKeyDown(KeyCode.UpArrow)) { //shop.SetActive(false); if (grounded) { jump = true; doubleJump = true; soundSource.clip = jumpSound; soundSource.Play(); } else if (doubleJump) { jump = true; doubleJump = false; soundSource.clip = jumpSound; soundSource.Play(); } } // salvem. if (Input.GetKeyDown("g")) { PosPlayer = GameObject.FindGameObjectWithTag("Player").transform.position; SysGuardar.Guardar_Posicion(PosPlayer); soundSource.clip = soundThunder; soundSource.Play(); anim.SetBool("ThunderBool", true); anim.Play("Thunder"); } if (Input.GetKeyDown("c")) { GameObject.FindGameObjectWithTag("Player").transform.position = SysGuardar.Cargar_Posicion(); soundSource.clip = soundThunder; soundSource.Play(); anim.SetBool("ThunderBool", true); anim.Play("Thunder"); } }