Advertisement
kadyr

Untitled

Sep 19th, 2021
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.11 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using DefaultNamespace;
  4. using UnityEngine;
  5.  
  6. public class Switch : MonoBehaviour
  7. {
  8. public GameObject riffle;
  9. public GameObject shotgun;
  10. public GameObject pistol;
  11.  
  12. private Gun currentGun;
  13.  
  14. int level = 1;
  15.  
  16. public enum Weapon
  17. {
  18. Pistol,
  19. Shotgun,
  20. Riffle
  21. }
  22. void Start()
  23. {
  24. switch (level)
  25. {
  26. case 1:
  27. ChooseWeapon(Weapon.Pistol);
  28. break;
  29. case 2:
  30. ChooseWeapon(Weapon.Shotgun);
  31. break;
  32. case 3:
  33. ChooseWeapon(Weapon.Riffle);
  34. break;
  35. default:
  36. print("Для этого уровня не подготовлено оружие");
  37. break;
  38. }
  39.  
  40. }
  41.  
  42. private void Update()
  43. {
  44. if(Input.GetMouseButton(0))
  45. currentGun.Shoot();
  46.  
  47.  
  48. if (Input.GetKeyDown(KeyCode.Alpha1))
  49. ChooseWeapon(Weapon.Pistol);
  50. if (Input.GetKeyDown(KeyCode.Alpha2))
  51. ChooseWeapon(Weapon.Shotgun);
  52. if (Input.GetKeyDown(KeyCode.Alpha3))
  53. ChooseWeapon(Weapon.Riffle);
  54. }
  55.  
  56. private void ChooseWeapon(Weapon weaponName)
  57. {
  58. switch (weaponName)
  59. {
  60. case Weapon.Pistol:
  61. riffle.SetActive(false);
  62. shotgun.SetActive(false);
  63. pistol.SetActive(true);
  64. currentGun = GetComponentInChildren<Pistol>();
  65. break;
  66. case Weapon.Shotgun:
  67. riffle.SetActive(false);
  68. shotgun.SetActive(true);
  69. pistol.SetActive(false);
  70. currentGun = GetComponentInChildren<Shotgun>();
  71. break;
  72. case Weapon.Riffle:
  73. riffle.SetActive(true);
  74. shotgun.SetActive(false);
  75. pistol.SetActive(false);
  76. currentGun = GetComponentInChildren<Riffle>();
  77. break;
  78. }
  79. }
  80. }
  81. using System.Collections;
  82. using System.Collections.Generic;
  83. using Photon.Realtime;
  84. using UnityEngine;
  85.  
  86. public class Pistol : Gun
  87. {
  88. private Quaternion pc;
  89.  
  90. void Start()
  91. {
  92. damage = 20;
  93. cooldown = 0.5f;
  94. speed = 25f;
  95. auto = false;
  96. pc = GetComponentInParent<PlayerController>().transform.rotation;
  97. }
  98.  
  99. protected override void OnShoot()
  100. {
  101. GameObject bol = Instantiate(bullet, riffleStart.transform.position,pc);
  102. bol.GetComponent<Bullet>().setDirection(GetComponentInParent<PlayerController>().transform.forward);
  103. }
  104. }
  105.  
  106. using System.Collections;
  107. using System.Collections.Generic;
  108. using UnityEngine;
  109.  
  110. public class Gun : MonoBehaviour
  111. {
  112. [SerializeField]
  113. protected Transform riffleStart;
  114.  
  115. [SerializeField]
  116. protected GameObject bullet;
  117.  
  118. protected int damage = 0;
  119. protected float speed = 20f;
  120. protected float cooldown = 0;
  121. protected bool auto = false;
  122.  
  123. private float timer = 0;
  124.  
  125. public void Shoot()
  126. {
  127. if (Input.GetMouseButtonDown(0) || auto)
  128. {
  129. if (timer > cooldown)
  130. {
  131. OnShoot();
  132. timer = 0;
  133. }
  134. }
  135. }
  136.  
  137. protected virtual void OnShoot(){ }
  138.  
  139. void Start()
  140. {
  141. timer = cooldown;
  142. }
  143.  
  144. // Update is called once per frame
  145. void Update()
  146. {
  147. timer += Time.deltaTime;
  148. }
  149. }
  150.  
  151. using ExitGames.Client.Photon.StructWrapping;
  152. using UnityEngine;
  153.  
  154. namespace DefaultNamespace
  155. {
  156. public class Shotgun:Gun
  157. {
  158. void Start()
  159. {
  160. damage = 5;
  161. auto = false;
  162. cooldown = 0;
  163. speed = 0;
  164. }
  165.  
  166. protected override void OnShoot()
  167. {
  168. for (int i = 0; i < 15; i++)
  169. {
  170. GameObject bul = Instantiate(bullet);
  171. bul.transform.position = riffleStart.transform.position;
  172. float x = Random.Range(-10, 10);
  173. float y = Random.Range(-15, 15);
  174. bul.transform.rotation = transform.rotation;
  175. bul.GetComponent<Bullet>().setDirection(transform.forward+new Vector3(x/100,y/100,0));
  176. }
  177. }
  178. }
  179. }
  180.  
  181. using UnityEngine;
  182. using UnityEngine.UI;
  183.  
  184. public class PlayerController : MonoBehaviour
  185. {
  186. [SerializeField]
  187. Text HpText;
  188.  
  189. int health;
  190.  
  191. [SerializeField]
  192. GameObject gameOver;
  193.  
  194. [SerializeField]
  195. GameObject pauseUI;
  196.  
  197. bool pause;
  198.  
  199. public void ChangeHealth(int count)
  200. {
  201. health = health + count;
  202. if (health <= 0)
  203. {
  204. gameOver.SetActive(true);
  205. GetComponent<PlayerLook>().enabled = false;
  206. Cursor.lockState = CursorLockMode.None;
  207. }
  208. // HpText.text = health.ToString();
  209. }
  210.  
  211. public int GetHealth()
  212. {
  213. return health;
  214. }
  215.  
  216. // Start is called before the first frame update
  217. void Start()
  218. {
  219. ChangeHealth(100);
  220. }
  221.  
  222. // Update is called once per frame
  223. void Update()
  224. {
  225. if (Input.GetKeyDown(KeyCode.Escape))
  226. {
  227. if (pause == true)
  228. {
  229. pause = false;
  230. GetComponent<PlayerLook>().enabled = true;
  231. GetComponent<PlayerMove>().enabled = true;
  232. Cursor.lockState = CursorLockMode.Locked;
  233. pauseUI.SetActive(false);
  234. }
  235. else
  236. {
  237. pause = true;
  238. GetComponent<PlayerLook>().enabled = false;
  239. GetComponent<PlayerMove>().enabled = false;
  240. Cursor.lockState = CursorLockMode.None;
  241. pauseUI.SetActive(true);
  242. }
  243. }
  244. }
  245.  
  246. private void OnTriggerEnter(Collider collider)
  247. {
  248. if (collider.tag == "Health")
  249. {
  250. print("health");
  251. Destroy(collider.gameObject);
  252. ChangeHealth(50);
  253. }
  254. }
  255. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement