예제 #1
0
        // Update whether or not the AI can fire this frame
        private void UpdateFiring()
        {
            float primaryFiringSolutionQuality = GetPrimaryFiringSolutionQuality();

            bool canFirePrimary = primaryFiringSolutionQuality > 0.5f;

            if (canFirePrimary)
            {
                // If weapon can fire but has not been firing, check if the cooling off period has finished before firing it again
                if (!isFiringPrimary)
                {
                    // If hasn't finished cooling off period, don't fire
                    if (Time.time - primaryWeaponActionStartTime < primaryWeaponActionPeriod)
                    {
                        canFirePrimary = false;
                    }
                    else
                    {
                        primaryWeaponActionStartTime = Time.time;
                        primaryWeaponActionPeriod    = Random.Range(minMaxPrimaryFiringPeriod.x, minMaxPrimaryFiringPeriod.y);
                        isFiringPrimary = true;
                    }
                }
                // If weapon can fire and has been firing, check if it has finished the firing period
                else
                {
                    // If weapon has been firing long enough, stop firing
                    if (Time.time - primaryWeaponActionStartTime > primaryWeaponActionPeriod)
                    {
                        canFirePrimary = false;
                        primaryWeaponActionStartTime = Time.time;
                        primaryWeaponActionPeriod    = Random.Range(minMaxPrimaryFiringInterval.x, minMaxPrimaryFiringInterval.y);
                        isFiringPrimary = false;
                    }
                }
            }

            if (canFirePrimary && primaryFiringSolutionQuality > 0.5f)
            {
                triggerablesManager.StartTriggeringAtIndex(0);
            }
            else
            {
                triggerablesManager.StopTriggeringAtIndex(0);
            }
        }
        protected virtual void SetPrimaryWeaponAction(bool fire)
        {
            if (fire)
            {
                triggerablesManager.StartTriggeringAtIndex(0);
                primaryWeaponFiring = true;

                primaryWeaponActionStartTime = Time.time;
                primaryWeaponActionPeriod    = Random.Range(minPrimaryFiringPeriod, maxPrimaryFiringPeriod);
            }
            else
            {
                triggerablesManager.StopTriggeringAtIndex(0);
                primaryWeaponFiring = false;

                primaryWeaponActionStartTime = Time.time;
                primaryWeaponActionPeriod    = Random.Range(minPrimaryFiringPause, maxPrimaryFiringPause);
            }
        }
예제 #3
0
 // Called to stop triggering at a specified index.
 public void TriggerUp(int triggerIndex)
 {
     triggerablesManager.StopTriggeringAtIndex(triggerIndex);
 }