Advertisement
kadyr

Untitled

Sep 19th, 2021
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Switch : MonoBehaviour
  6. {
  7. public GameObject riffle;
  8. public GameObject shotgun;
  9. public GameObject pistol;
  10.  
  11. private Gun currentGun;
  12.  
  13. int level = 1;
  14.  
  15. public enum Weapon
  16. {
  17. Pistol,
  18. Shotgun,
  19. Riffle
  20. }
  21. void Start()
  22. {
  23. switch (level)
  24. {
  25. case 1:
  26. ChooseWeapon(Weapon.Pistol);
  27. break;
  28. case 2:
  29. ChooseWeapon(Weapon.Shotgun);
  30. break;
  31. case 3:
  32. ChooseWeapon(Weapon.Riffle);
  33. break;
  34. default:
  35. print("Для этого уровня не подготовлено оружие");
  36. break;
  37. }
  38.  
  39. }
  40.  
  41. private void Update()
  42. {
  43. if(Input.GetMouseButton(0))
  44. currentGun.Shoot();
  45.  
  46.  
  47. if (Input.GetKeyDown(KeyCode.Alpha1))
  48. ChooseWeapon(Weapon.Pistol);
  49. if (Input.GetKeyDown(KeyCode.Alpha2))
  50. ChooseWeapon(Weapon.Shotgun);
  51. if (Input.GetKeyDown(KeyCode.Alpha3))
  52. ChooseWeapon(Weapon.Riffle);
  53. }
  54.  
  55. private void ChooseWeapon(Weapon weaponName)
  56. {
  57. switch (weaponName)
  58. {
  59. case Weapon.Pistol:
  60. riffle.SetActive(false);
  61. shotgun.SetActive(false);
  62. pistol.SetActive(true);
  63. currentGun = GetComponentInChildren<Pistol>();
  64. break;
  65. case Weapon.Shotgun:
  66. riffle.SetActive(false);
  67. shotgun.SetActive(true);
  68. pistol.SetActive(false);
  69. break;
  70. case Weapon.Riffle:
  71. riffle.SetActive(true);
  72. shotgun.SetActive(false);
  73. pistol.SetActive(false);
  74. currentGun = GetComponentInChildren<Riffle>();
  75. break;
  76. }
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement