Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using Sirenix.OdinInspector;
- using UnityEngine;
- using UnityEngine.Events;
- [System.Serializable]
- [HideLabel]
- public class GunClip
- {
- internal int CurrentAmmo = 0;
- internal int MaxAmmo = 3;
- private float _currentReloadTime;
- private float _currentDelayTime;
- private bool _weaponLoading;
- private bool _weaponLocked;
- [SuffixLabel("Second(s)", Overlay = true), ShowInInspector] public float maxReloadTime;
- [SuffixLabel("Second(s)", Overlay = true), ShowInInspector] public float maxDelayTime;
- public Dictionary<string, Vector2> ClipUI_Info()
- {
- var ammoUI = new Vector2(CurrentAmmo, MaxAmmo);
- var reloadUI = new Vector2(_currentReloadTime, maxReloadTime);
- var delayUI = new Vector2(_currentDelayTime, maxDelayTime);
- var clipInfo = new Dictionary<string, Vector2> {{"ammo", ammoUI}, {"reload", reloadUI}, {"delay", delayUI}};
- return
- clipInfo;
- }
- internal bool WeaponLocked()
- {
- return _weaponLocked;
- }
- internal void InternalUpdate()
- {
- CountUp();
- if (CurrentAmmo < MaxAmmo && !_weaponLoading)
- StartReload();
- if (_currentReloadTime >= maxReloadTime)
- FinishReload();
- _weaponLoading = _currentReloadTime <= maxReloadTime;
- _weaponLocked = _currentDelayTime <= maxDelayTime;
- }
- internal void StartDelay()
- {
- _currentDelayTime = 0;
- }
- private void CountUp()
- {
- if (_currentReloadTime < maxReloadTime)
- _currentReloadTime += Time.fixedDeltaTime;
- if (_currentDelayTime < maxDelayTime)
- _currentDelayTime += Time.fixedDeltaTime;
- }
- private void StartReload()
- {
- _currentReloadTime = 0;
- }
- private void FinishReload()
- {
- CurrentAmmo = MaxAmmo;
- _weaponLoading = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement