Advertisement
kadyr

Untitled

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