Advertisement
kadyr

Untitled

Sep 19th, 2021
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 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.GetKeyDown(KeyCode.Alpha1))
  44. ChooseWeapon(Weapon.Pistol);
  45. if (Input.GetKeyDown(KeyCode.Alpha2))
  46. ChooseWeapon(Weapon.Shotgun);
  47. if (Input.GetKeyDown(KeyCode.Alpha3))
  48. ChooseWeapon(Weapon.Riffle);
  49. }
  50.  
  51. private void ChooseWeapon(Weapon weaponName)
  52. {
  53. switch (weaponName)
  54. {
  55. case Weapon.Pistol:
  56. riffle.SetActive(false);
  57. shotgun.SetActive(false);
  58. pistol.SetActive(true);
  59. break;
  60. case Weapon.Shotgun:
  61. riffle.SetActive(false);
  62. shotgun.SetActive(true);
  63. pistol.SetActive(false);
  64. break;
  65. case Weapon.Riffle:
  66. riffle.SetActive(true);
  67. shotgun.SetActive(false);
  68. pistol.SetActive(false);
  69. break;
  70. }
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement