Advertisement
kadyr

Untitled

Oct 16th, 2021
871
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.04 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.     private void ChooseWeapon(Weapons weaponName)
  59.     {
  60.         switch (weaponName)
  61.         {
  62.             case Weapons.Pistol:
  63.                 pistol.SetActive(true);
  64.                 shotGun.SetActive(false);
  65.                 riffle.SetActive(false);
  66.                 currentGun = GetComponentInChildren<Pistol>();
  67.                 break;
  68.             case Weapons.Shotgun:
  69.                 pistol.SetActive(false);
  70.                 shotGun.SetActive(true);
  71.                 riffle.SetActive(false);
  72.                 //todo : add shotgub
  73.                 break;
  74.             case Weapons.Riffle:
  75.                 pistol.SetActive(false);
  76.                 shotGun.SetActive(false);
  77.                 riffle.SetActive(true);
  78.                 currentGun = GetComponentInChildren<Riffle>();
  79.                 break;
  80.         }
  81.     }
  82. }
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement