Exemplo n.º 1
0
    /// <summary>
    /// Launches a spawned missile at the given target.
    /// </summary>
    /// <param name="target">If no target is given, the missile will fire without guidance.</param>
    /// <param name="velocity">Used to give a missile with a drop delay an initial velocity. Typical
    /// use case would be passing in the velocity of the launching platform.</param>
    public override void Launch(Transform target, Vector3 velocity)
    {
        if (missileCount > 0 && reloadCooldown <= 0.0f && magazineReloadCooldown <= 0.0f)
        {
            if (fireSource != null)
                fireSource.Play();

            // Random deviation.
            Vector3 deviation = UnityEngine.Random.insideUnitCircle * (dispersionAngle * Mathf.Deg2Rad);
            deviation = launchPoints[tubeCount].TransformDirection(deviation);
            Vector3 randomizedForward = launchPoints[tubeCount].forward + deviation;
            Quaternion randomizedRotation = Quaternion.LookRotation(randomizedForward);

            AAMissile missile = CreateMissile(launchPoints[tubeCount].position, randomizedRotation);
            missile.target = target;
            missile.Launch(target, velocity);
            reloadCooldown = fireDelay;

            missileCount--;

            // Cycle through launch points.
            tubeCount++;
            if (tubeCount >= launchPoints.Count)
                tubeCount = 0;

            // Reload magazine if all out of missiles.
            if (missileCount <= 0)
                ReloadMagazine();
        }
    }
Exemplo n.º 2
0
        /// <param name="target">If no target is given, the missile will fire without guidance.</param>
        /// <param name="inheritedVelocity">Used to give a missile with a drop delay an initial velocity. Typical
        /// use case would be passing in the velocity of the launching platform.</param>
        public bool Launch(Transform target, Vector3 inheritedVelocity)
        {
            bool successfulLaunch = false;

            if (loadedMissile != null)
            {
                loadedMissile.Launch(target, inheritedVelocity);
                loadedMissile = null;
                cooldown      = reloadTime;

                successfulLaunch = true;
            }

            return(successfulLaunch);
        }