Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.UI;
- public class PlayerController : MonoBehaviour
- {
- [SerializeField] Text HpText;
- int health;
- [SerializeField] GameObject bullet;
- [SerializeField] GameObject rifleStart;
- [SerializeField] GameObject gameOver;
- [SerializeField] GameObject pauseUI;
- bool pause = false;
- public void ChangeHealth(int count)
- {
- health = health + count;
- if (health <= 0)
- {
- gameOver.SetActive(true);
- GetComponent<PlayerLook>().enabled = false;
- Cursor.lockState = CursorLockMode.None;
- }
- HpText.text = health.ToString();
- }
- public int GetHealth()
- {
- return health;
- }
- // Start is called before the first frame update
- void Start()
- {
- //+++++++++++++++++++++++
- if (PlayerPrefs.HasKey("playerX"))
- {
- float x = PlayerPrefs.GetFloat("playerX");
- float y = PlayerPrefs.GetFloat("playerY");
- float z = PlayerPrefs.GetFloat("playerZ");
- ChangeHealth(PlayerPrefs.GetInt("health"));
- transform.position = new Vector3(x, y, z);
- }
- else
- {
- ChangeHealth(100);
- }
- //++++++++++++++++++++++++++++
- }
- // Update is called once per frame
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.Escape))
- {
- if (pause)
- {
- pause = false;
- GetComponent<PlayerLook>().enabled = true;
- GetComponent<PlayerMove>().enabled = true;
- Cursor.lockState = CursorLockMode.Locked;
- pauseUI.SetActive(false);
- }
- else
- {
- pause = true;
- GetComponent<PlayerLook>().enabled = false;
- GetComponent<PlayerMove>().enabled = false;
- Cursor.lockState = CursorLockMode.None;
- pauseUI.SetActive(true);
- }
- }
- if (Input.GetMouseButtonDown(0) && !pause)
- {
- //создаем пулю
- GameObject buf = Instantiate(bullet);
- buf.transform.position = rifleStart.transform.position;
- buf.transform.rotation = transform.rotation;
- buf.GetComponent<Bullet>().setDirection(transform.forward);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement