Advertisement
kadyr

Untitled

Jul 31st, 2021
152
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. public void StartGame()
  33. {
  34. SceneManager.LoadScene(1); //указываем номер сцены для загрузки
  35. }
  36.  
  37. public void Back()
  38. {
  39. SceneManager.LoadScene(0);
  40. }
  41.  
  42. public void Credits()
  43. {
  44. SceneManager.LoadScene(2);
  45. }
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement