Advertisement
Guest User

weapon_reloader

a guest
Feb 19th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class WeaponReloader : MonoBehaviour {
  6.  
  7. [SerializeField]int maxAmmo;
  8. [SerializeField]float reloadTime;
  9. [SerializeField]int clipSize;
  10.  
  11. int ammo;
  12. public int shotsFiredInClip;
  13. bool isReloading;
  14.  
  15. public int RoundsRemainingInClip {
  16. get {
  17. return clipSize - shotsFiredInClip;
  18. }
  19. }
  20.  
  21. public bool IsReloading {
  22. get {
  23. return isReloading;
  24. }
  25.  
  26. }
  27.  
  28. public void Reload() {
  29. if(isReloading)
  30. return;
  31.  
  32. print ("Reload started");
  33. isReloading = true;
  34. GameManager.Instance.Timer.Add(ExecuteReload, reloadTime);
  35. }
  36.  
  37. private void ExecuteReload() {
  38.  
  39. print ("Reload executed!");
  40. isReloading = false;
  41. ammo -= shotsFiredInClip;
  42. shotsFiredInClip = 0;
  43.  
  44. if(ammo < 0) {
  45. ammo = 0;
  46. shotsFiredInClip += -ammo;
  47. }
  48.  
  49. }
  50.  
  51. public void TakeFromClip(int amount) {
  52. shotsFiredInClip += amount;
  53. }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement