Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using UnityEngine;
- public enum AmmoType
- {
- Pistol,
- AK47
- }
- public class Weapon : MonoBehaviour
- {
- private int currentClip;
- private int clipSize;
- private AmmoSlot ammoSlot;
- private AmmoType ammoType;
- private void Reload()
- {
- if (Input.GetKeyDown(KeyCode.R) && currentClip < clipSize && ammoSlot.GetCurrentAmmo(ammoType) > 0)
- {
- int missingClip = clipSize - currentClip;
- if (ammoSlot.GetCurrentAmmo(ammoType) >= missingClip)
- {
- currentClip += missingClip;
- ammoSlot.ReduceCurrentAmmo(ammoType, missingClip);
- }
- else
- {
- currentClip += ammoSlot.GetCurrentAmmo(ammoType);
- ammoSlot.ReduceCurrentAmmo(ammoType, ammoSlot.GetCurrentAmmo(ammoType));
- }
- }
- }
- }
- public class AmmoSlot : MonoBehaviour
- {
- private Dictionary<AmmoType, int> _ammos = new Dictionary<AmmoType, int>();
- public int GetCurrentAmmo(AmmoType ammoType)
- {
- return _ammos[ammoType];
- }
- public void ReduceCurrentAmmo(AmmoType ammoType, int missingClip)
- {
- _ammos[ammoType] -= missingClip;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement