Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using Photon.Realtime;
- using UnityEngine;
- public class WeaponSwitcher : MonoBehaviour
- {
- [SerializeField]
- private GameObject riffle;
- [SerializeField]
- private GameObject pistol;
- [SerializeField]
- private GameObject shotGun;
- enum Weapons
- {
- Pistol,
- Shotgun,
- Riffle
- }
- private Weapons weapon = Weapons.Pistol;
- private Gun currentGun;
- private int level = 1;
- void Start()
- {
- switch (level)
- {
- case 1:
- ChooseWeapon(Weapons.Pistol);
- break;
- case 2:
- ChooseWeapon(Weapons.Shotgun);
- break;
- case 3:
- ChooseWeapon(Weapons.Riffle);
- break;
- }
- }
- private void Update()
- {
- if (Input.GetKeyDown(KeyCode.Alpha1))
- {
- ChooseWeapon(Weapons.Pistol);
- }
- if (Input.GetKeyDown(KeyCode.Alpha2))
- {
- ChooseWeapon(Weapons.Shotgun);
- }
- if (Input.GetKeyDown(KeyCode.Alpha3))
- {
- ChooseWeapon(Weapons.Riffle);
- }
- }
- private void ChooseWeapon(Weapons weaponName)
- {
- switch (weaponName)
- {
- case Weapons.Pistol:
- pistol.SetActive(true);
- shotGun.SetActive(false);
- riffle.SetActive(false);
- currentGun = GetComponentInChildren<Pistol>();
- break;
- case Weapons.Shotgun:
- pistol.SetActive(false);
- shotGun.SetActive(true);
- riffle.SetActive(false);
- //todo : add shotgub
- break;
- case Weapons.Riffle:
- pistol.SetActive(false);
- shotGun.SetActive(false);
- riffle.SetActive(true);
- currentGun = GetComponentInChildren<Riffle>();
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement