Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Switch : MonoBehaviour
- {
- public GameObject riffle;
- public GameObject shotgun;
- public GameObject pistol;
- private Gun currentGun;
- int level = 1;
- public enum Weapon
- {
- Pistol,
- Shotgun,
- Riffle
- }
- void Start()
- {
- switch (level)
- {
- case 1:
- ChooseWeapon(Weapon.Pistol);
- break;
- case 2:
- ChooseWeapon(Weapon.Shotgun);
- break;
- case 3:
- ChooseWeapon(Weapon.Riffle);
- break;
- default:
- print("Для этого уровня не подготовлено оружие");
- break;
- }
- }
- private void Update()
- {
- if (Input.GetKeyDown(KeyCode.Alpha1))
- ChooseWeapon(Weapon.Pistol);
- if (Input.GetKeyDown(KeyCode.Alpha2))
- ChooseWeapon(Weapon.Shotgun);
- if (Input.GetKeyDown(KeyCode.Alpha3))
- ChooseWeapon(Weapon.Riffle);
- }
- private void ChooseWeapon(Weapon weaponName)
- {
- switch (weaponName)
- {
- case Weapon.Pistol:
- riffle.SetActive(false);
- shotgun.SetActive(false);
- pistol.SetActive(true);
- break;
- case Weapon.Shotgun:
- riffle.SetActive(false);
- shotgun.SetActive(true);
- pistol.SetActive(false);
- break;
- case Weapon.Riffle:
- riffle.SetActive(true);
- shotgun.SetActive(false);
- pistol.SetActive(false);
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement