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; } } }