TimedWeapon.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using UnityEngine;
  2. using System.Collections;
  3. public class TimedWeapon : Weapon
  4. {
  5. public float time;
  6. public int fireRatePerMinute;
  7. int _ticksLeftToReset;
  8. int _ticksBetweenFires;
  9. int _ticksToNextFire;
  10. public override void Arm()
  11. {
  12. base.Arm();
  13. _ticksLeftToReset = (int)(time / Time.fixedDeltaTime);
  14. float timeBetweenFires = 60.0f / fireRatePerMinute;
  15. _ticksBetweenFires = (int)(timeBetweenFires / Time.fixedDeltaTime);
  16. _ticksToNextFire = _ticksBetweenFires;
  17. }
  18. public override void UpdateWeapon()
  19. {
  20. if (!RecordingManager.Instance.IsPlayingBack)//don't shoot from mouse during playing back
  21. {
  22. --_ticksToNextFire;
  23. if (_ticksToNextFire == 0)
  24. {
  25. NotificationCenter.Post(NotificationType.Fire, new Vector2(Input.mousePosition.x, Input.mousePosition.y));
  26. _ticksToNextFire += _ticksBetweenFires;
  27. }
  28. }
  29. --_ticksLeftToReset;
  30. NotificationCenter.Post(NotificationType.UpdateWeaponUpgradeTimeLeft, GetTimeLeft());
  31. }
  32. int GetTimeLeft()
  33. {
  34. return (int)(_ticksLeftToReset * Time.fixedDeltaTime);
  35. }
  36. public override bool IsEmpty
  37. {
  38. get
  39. {
  40. return GetTimeLeft() <= 0;
  41. }
  42. }
  43. }