Advertisement
kadyr

ff

Jul 6th, 2021
1,039
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.69 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class PlayerController: MonoBehaviour {
  7.   public int Medicine;
  8.   public int HP;
  9.   [SerializeField] Text HPText;
  10.   [SerializeField] GameObject bullet;
  11.   [SerializeField] GameObject rifleStart;
  12.   [SerializeField] Text MedicineText;
  13.   [SerializeField] GameObject GameOver;
  14.   private LineRenderer Laser;
  15.  
  16.   // Start is called before the first frame update
  17.   void Start() {
  18.     HP = 100;
  19.     if (HP <= 0) {
  20.       GameOver.SetActive(true);
  21.       GetComponent < PlayerLook > ().enabled = false;
  22.       Cursor.lockState = CursorLockMode.None;
  23.     }
  24.     Medicine = 1;
  25.  
  26.   }
  27.  
  28.   public void ChangeMedicine(int count) {
  29.     Medicine += count;
  30.     if (Medicine <= 0) {
  31.       Medicine = 0;
  32.  
  33.     }
  34.   }
  35.   public void ChangeHealth(int count) {
  36.     HP += count;
  37.     if (HP <= 0) {
  38.       GameOver.SetActive(true);
  39.       GetComponent < PlayerLook > ().enabled = false;
  40.       Cursor.lockState = CursorLockMode.None;
  41.       HP = 0;
  42.     }
  43.     if (HP > 100)
  44.       HP = 100;
  45.  
  46.   }
  47.   public void OnTriggerEnter(Collider collider) {
  48.  
  49.     if (collider.tag == "Killer")
  50.       ChangeHealth(-20);
  51.     Destroy(collider.gameObject);
  52.     if (collider.tag == "tomato")
  53.       ChangeHealth(+20);
  54.     Destroy(collider.gameObject);
  55.   }
  56.   void Update() {
  57.     HPText.text = HP.ToString();
  58.     MedicineText.text = Medicine.ToString();
  59.  
  60.     if (Input.GetMouseButtonDown(0)) {
  61.       // GameObject buf = Instantiate(bullet);
  62.       GameObject buf = Instantiate(bullet, rifleStart.transform.position, rifleStart.transform.rotation);
  63.       // buf.transform.position = rifleStart.transform.position;
  64.       buf.GetComponent < Bullet > ().setDirection(transform.forward);
  65.       Debug.Log("Fire!");
  66.       // buf.transform.rotation = transform.rotation;
  67.     }
  68.  
  69.   }
  70. }
  71. using System.Collections;
  72. using System.Collections.Generic;
  73. using UnityEngine;
  74. using UnityEngine.UI;
  75.  
  76. public class PlayerController: MonoBehaviour {
  77.   public int Medicine;
  78.   public int HP;
  79.   [SerializeField] Text HPText;
  80.   [SerializeField] GameObject bullet;
  81.   [SerializeField] GameObject rifleStart;
  82.   [SerializeField] Text MedicineText;
  83.   [SerializeField] GameObject GameOver;
  84.   private LineRenderer Laser;
  85.  
  86.   // Start is called before the first frame update
  87.   void Start() {
  88.     HP = 100;
  89.     if (HP <= 0) {
  90.       GameOver.SetActive(true);
  91.       GetComponent < PlayerLook > ().enabled = false;
  92.       Cursor.lockState = CursorLockMode.None;
  93.     }
  94.     Medicine = 1;
  95.  
  96.   }
  97.  
  98.   public void ChangeMedicine(int count) {
  99.     Medicine += count;
  100.     if (Medicine <= 0) {
  101.       Medicine = 0;
  102.  
  103.     }
  104.   }
  105.   public void ChangeHealth(int count) {
  106.     HP += count;
  107.     if (HP <= 0) {
  108.       GameOver.SetActive(true);
  109.       GetComponent < PlayerLook > ().enabled = false;
  110.       Cursor.lockState = CursorLockMode.None;
  111.       HP = 0;
  112.     }
  113.     if (HP > 100)
  114.       HP = 100;
  115.  
  116.   }
  117.   public void OnTriggerEnter(Collider collider) {
  118.  
  119.     if (collider.tag == "Killer")
  120.       ChangeHealth(-20);
  121.     Destroy(collider.gameObject);
  122.     if (collider.tag == "tomato")
  123.       ChangeHealth(+20);
  124.     Destroy(collider.gameObject);
  125.   }
  126.   void Update() {
  127.     HPText.text = HP.ToString();
  128.     MedicineText.text = Medicine.ToString();
  129.  
  130.     if (Input.GetMouseButtonDown(0)) {
  131.       // GameObject buf = Instantiate(bullet);
  132.       GameObject buf = Instantiate(bullet, rifleStart.transform.position, rifleStart.transform.rotation);
  133.       // buf.transform.position = rifleStart.transform.position;
  134.       buf.GetComponent < Bullet > ().setDirection(transform.forward);
  135.       Debug.Log("Fire!");
  136.       // buf.transform.rotation = transform.rotation;
  137.     }
  138.  
  139.   }
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement