Ejemplo n.º 1
0
    /// <summary>
    /// Attempts to attack the current target with the equipped weapon
    /// </summary>
    private void AttackTarget(AIController controller)
    {
        if(controller.target == null) {
            return;
        }

        // Direction to the target
        Vector3 toTarget = (controller.transform.position - controller.target.transform.position);

        if(!isBursting) {
            // Check if enough delay has past to start another burst
            if(Time.time - lastBurstTime > currentBurstDelay && CanShootTarget(controller)) {

                lastBurstTime = Time.time;
                isBursting = true;

                currentBurstLength = controller.GetFireBurstLength();//Random.Range(0.1f, 1.0f);
                currentBurstDelay = currentBurstLength + Random.Range(minBurstInterval, maxBurstInterval);

                StartShooting(controller);
            }
        }
        else {
            // Is in the middle of shooting the weapon
            if(Time.time - lastBurstTime > currentBurstLength) {
                // Cancel the burst
                isBursting = false;
                StopShooting(controller);
            }
            else if(!CanShootTarget(controller)) {
                // if at any point in the burst, the ai cant see target, end the burst
                isBursting = false;
                StopShooting(controller);
            }

        }
    }