Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public enum Weapon{
- Police9mm,
- PortableMagnum,
- }
- public class WeaponManager : MonoBehaviour {
- public static WeaponManager instance;
- private int currentWeaponIndex = 0;
- private Weapon[] weapons = { Weapon.Police9mm, Weapon.Police9mm };
- void Awake(){
- if(instance == null){
- instance = this;
- }
- else{
- Destroy(gameObject);
- }
- }
- void Start(){
- SwitchTocurrentWeapon();
- }
- void Update(){
- CheckWeaponSwitch();
- }
- void SwitchTocurrentWeapon(){
- for(int i = 0; i < transform.childCount; i++){
- transform.GetChild(i).gameObject.SetActive(false);
- }
- transform.Find(weapons[currentWeaponIndex].ToString()).gameObject.SetActive(true);
- }
- void CheckWeaponSwitch(){
- float mousewheel = Input.GetAxis("Mouse ScrollWheel");
- // Forward
- if(mousewheel > 0){
- SelectPreviousWeapon();
- }
- // Backward
- else if(mousewheel < 0){
- SelectNextWeapon();
- }
- }
- void SelectPreviousWeapon() {
- if(currentWeaponIndex == 0) {
- currentWeaponIndex = weapons.Length - 1;
- }
- else {
- currentWeaponIndex++;
- }
- SwitchTocurrentWeapon();
- }
- void SelectNextWeapon() {
- if(currentWeaponIndex >= (weapons.Length - 1)) {
- currentWeaponIndex = 0;
- }
- else {
- currentWeaponIndex++;
- }
- SwitchTocurrentWeapon();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement