1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- using UnityEngine;
- using System.Collections;
- public class TimedWeapon : Weapon
- {
- public float time;
- public int fireRatePerMinute;
- int _ticksLeftToReset;
- int _ticksBetweenFires;
- int _ticksToNextFire;
- public override void Arm()
- {
- base.Arm();
- _ticksLeftToReset = (int)(time / Time.fixedDeltaTime);
- float timeBetweenFires = 60.0f / fireRatePerMinute;
- _ticksBetweenFires = (int)(timeBetweenFires / Time.fixedDeltaTime);
- _ticksToNextFire = _ticksBetweenFires;
- }
- public override void UpdateWeapon()
- {
- if (!RecordingManager.Instance.IsPlayingBack)//don't shoot from mouse during playing back
- {
- --_ticksToNextFire;
- if (_ticksToNextFire == 0)
- {
- NotificationCenter.Post(NotificationType.Fire, new Vector2(Input.mousePosition.x, Input.mousePosition.y));
- _ticksToNextFire += _ticksBetweenFires;
- }
- }
- --_ticksLeftToReset;
- NotificationCenter.Post(NotificationType.UpdateWeaponUpgradeTimeLeft, GetTimeLeft());
- }
- int GetTimeLeft()
- {
- return (int)(_ticksLeftToReset * Time.fixedDeltaTime);
- }
- public override bool IsEmpty
- {
- get
- {
- return GetTimeLeft() <= 0;
- }
- }
- }
|