Advertisement
kadyr

Untitled

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