kadyr

Untitled

Jul 31st, 2021
1,078
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.         Debug.Log("SAVED!");
  22.     }
  23.  
  24.     public void LoadData()
  25.     {
  26.         float x = PlayerPrefs.GetFloat("playerX");
  27.         float y = PlayerPrefs.GetFloat("playerY");
  28.         float z = PlayerPrefs.GetFloat("playerZ");
  29.         int hp = PlayerPrefs.GetInt("health");
  30.         player.transform.position = new Vector3(x, y, z);
  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.  
RAW Paste Data