Advertisement
kadyr

Untitled

Jul 31st, 2021
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3.  
  4. public class PlayerController : MonoBehaviour
  5. {
  6. [SerializeField] Text HpText;
  7. int health;
  8.  
  9. [SerializeField] GameObject bullet;
  10. [SerializeField] GameObject rifleStart;
  11. [SerializeField] GameObject gameOver;
  12. [SerializeField] GameObject pauseUI;
  13.  
  14. bool pause = false;
  15.  
  16. public void ChangeHealth(int count)
  17. {
  18. health = health + count;
  19. if (health <= 0)
  20. {
  21. gameOver.SetActive(true);
  22. GetComponent<PlayerLook>().enabled = false;
  23. Cursor.lockState = CursorLockMode.None;
  24. }
  25. HpText.text = health.ToString();
  26. }
  27.  
  28. public int GetHealth()
  29. {
  30. return health;
  31. }
  32.  
  33. // Start is called before the first frame update
  34. void Start()
  35. {
  36. //+++++++++++++++++++++++
  37. if (PlayerPrefs.HasKey("playerX"))
  38. {
  39. float x = PlayerPrefs.GetFloat("playerX");
  40. float y = PlayerPrefs.GetFloat("playerY");
  41. float z = PlayerPrefs.GetFloat("playerZ");
  42. ChangeHealth(PlayerPrefs.GetInt("health"));
  43. transform.position = new Vector3(x, y, z);
  44. Debug.Log("yea");
  45. }
  46. else
  47. {
  48. ChangeHealth(100);
  49. }
  50. //++++++++++++++++++++++++++++
  51. }
  52.  
  53. // Update is called once per frame
  54. void Update()
  55. {
  56. if (Input.GetKeyDown(KeyCode.Escape))
  57. {
  58. if (pause)
  59. {
  60. pause = false;
  61. GetComponent<PlayerLook>().enabled = true;
  62. GetComponent<PlayerMove>().enabled = true;
  63. Cursor.lockState = CursorLockMode.Locked;
  64. pauseUI.SetActive(false);
  65. }
  66. else
  67. {
  68. pause = true;
  69. GetComponent<PlayerLook>().enabled = false;
  70. GetComponent<PlayerMove>().enabled = false;
  71. Cursor.lockState = CursorLockMode.None;
  72. pauseUI.SetActive(true);
  73. }
  74. }
  75.  
  76. if (Input.GetMouseButtonDown(0) && !pause)
  77. {
  78. //создаем пулю
  79. GameObject buf = Instantiate(bullet);
  80. buf.transform.position = rifleStart.transform.position;
  81. buf.transform.rotation = transform.rotation;
  82. buf.GetComponent<Bullet>().setDirection(transform.forward);
  83. }
  84. }
  85. }
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement