Advertisement
kadyr

Untitled

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