Advertisement
kadyr

Untitled

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