Advertisement
kadyr

Untitled

Oct 10th, 2021
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class WeaponSwitcher : MonoBehaviour
  6. {
  7. [SerializeField]
  8. private GameObject riffle;
  9.  
  10. [SerializeField]
  11. private GameObject pistol;
  12.  
  13. [SerializeField]
  14. private GameObject shotGun;
  15.  
  16. enum Weapons
  17. {
  18. Pistol,
  19. Shotgun,
  20. Riffle
  21. }
  22.  
  23. private Weapons weapon = Weapons.Pistol;
  24. private int level = 1;
  25. void Start()
  26. {
  27. switch (level)
  28. {
  29. case 1:
  30. ChooseWeapon(Weapons.Pistol);
  31. break;
  32. case 2:
  33. ChooseWeapon(Weapons.Shotgun);
  34. break;
  35. case 3:
  36. ChooseWeapon(Weapons.Riffle);
  37. break;
  38. }
  39. }
  40.  
  41. private void Update()
  42. {
  43. if (Input.GetKeyDown(KeyCode.Alpha1))
  44. {
  45. ChooseWeapon(Weapons.Pistol);
  46. }
  47. if (Input.GetKeyDown(KeyCode.Alpha2))
  48. {
  49. ChooseWeapon(Weapons.Shotgun);
  50. }
  51. if (Input.GetKeyDown(KeyCode.Alpha3))
  52. {
  53. ChooseWeapon(Weapons.Riffle);
  54. }
  55. }
  56. private void ChooseWeapon(Weapons weaponName)
  57. {
  58. switch (weaponName)
  59. {
  60. case Weapons.Pistol:
  61. pistol.SetActive(true);
  62. shotGun.SetActive(false);
  63. riffle.SetActive(false);
  64. break;
  65. case Weapons.Shotgun:
  66. pistol.SetActive(false);
  67. shotGun.SetActive(true);
  68. riffle.SetActive(false);
  69. break;
  70. case Weapons.Riffle:
  71. pistol.SetActive(false);
  72. shotGun.SetActive(false);
  73. riffle.SetActive(true);
  74. break;
  75. }
  76. }
  77. }
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement