Advertisement
kadyr

Untitled

Aug 7th, 2021
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. using UnityEngine.SceneManagement;
  4.  
  5. public class Menu : MonoBehaviour
  6. {
  7. public GameObject player;
  8. private void Start()
  9. {
  10.  
  11. }
  12.  
  13. public void SaveData()
  14. {
  15. Vector3 position = player.transform.position;
  16. int health = player.GetComponent<PlayerController>().GetHealth();
  17. PlayerPrefs.SetFloat("playerX", position.x);
  18. PlayerPrefs.SetFloat("playerY", position.y);
  19. PlayerPrefs.SetFloat("playerZ", position.z);
  20. PlayerPrefs.SetInt("health", health);
  21. PlayerPrefs.Save();
  22. Debug.Log("SAVED!");
  23. }
  24.  
  25. public void LoadData()
  26. {
  27. float x = PlayerPrefs.GetFloat("playerX");
  28. float y = PlayerPrefs.GetFloat("playerY");
  29. float z = PlayerPrefs.GetFloat("playerZ");
  30. int hp = PlayerPrefs.GetInt("health");
  31. player.transform.position = new Vector3(x, y, z);
  32. }
  33.  
  34. public void StartGame()
  35. {
  36. SceneManager.LoadScene(1); //указываем номер сцены для загрузки
  37. }
  38.  
  39. public void Back()
  40. {
  41. SceneManager.LoadScene(0);
  42. }
  43.  
  44. public void Credits()
  45. {
  46. SceneManager.LoadScene(2);
  47. }
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement