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 WeaponReloader : MonoBehaviour {
- [SerializeField]int maxAmmo;
- [SerializeField]float reloadTime;
- [SerializeField]int clipSize;
- int ammo;
- public int shotsFiredInClip;
- bool isReloading;
- public int RoundsRemainingInClip {
- get {
- return clipSize - shotsFiredInClip;
- }
- }
- public bool IsReloading {
- get {
- return isReloading;
- }
- }
- public void Reload() {
- if(isReloading)
- return;
- print ("Reload started");
- isReloading = true;
- GameManager.Instance.Timer.Add(ExecuteReload, reloadTime);
- }
- private void ExecuteReload() {
- print ("Reload executed!");
- isReloading = false;
- ammo -= shotsFiredInClip;
- shotsFiredInClip = 0;
- if(ammo < 0) {
- ammo = 0;
- shotsFiredInClip += -ammo;
- }
- }
- public void TakeFromClip(int amount) {
- shotsFiredInClip += amount;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement