Exemplo n.º 1
0
    private void Awake()
    {
        transform = GetComponent <Transform>();
        missile   = GetComponent <AAMissile>();

        if (fireClip != null)
        {
            fireSource                       = gameObject.AddComponent <AudioSource>();
            fireSource.clip                  = fireClip;
            fireSource.minDistance           = fireMinDistance;
            fireSource.maxDistance           = fireMaxDistance;
            fireSource.loop                  = false;
            fireSource.dopplerLevel          = 0.0f;
            fireSource.spatialBlend          = 1.0f;
            fireSource.volume                = fireVolume;
            fireSource.pitch                 = Random.Range(0.9f, 1.3f);
            fireSource.outputAudioMixerGroup = mixerGroup ?? null;
            fireSource.Stop();
        }

        if (loopClip != null)
        {
            loopSource                       = gameObject.AddComponent <AudioSource>();
            loopSource.clip                  = loopClip;
            loopSource.minDistance           = loopMinDistance;
            loopSource.maxDistance           = loopMaxDistance;
            loopSource.loop                  = true;
            loopSource.dopplerLevel          = 1.0f;
            loopSource.volume                = loopVolume;
            loopSource.spatialBlend          = 1.0f;
            loopSource.outputAudioMixerGroup = mixerGroup ?? null;
            loopSource.Stop();
        }
    }
Exemplo n.º 2
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.º 3
0
    /// <summary>
    /// Spawns and fires a missile.
    /// </summary>
    /// <param name="position">Where the missile spawns.</param>
    /// <param name="rotation">Initial rotation of the missile.</param>
    /// <returns></returns>
    private AAMissile CreateMissile(Vector3 position, Quaternion rotation)
    {
        AAMissile mis = Instantiate(missilePrefabToLaunch) as AAMissile;
        mis.ownShip = ownShip;
        mis.transform.position = position;
        mis.transform.rotation = rotation;

        return mis;
    }
Exemplo n.º 4
0
        public void ClearHardpoint()
        {
            if (loadedMissile != null)
            {
                Destroy(loadedMissile.gameObject);
                loadedMissile = null;
            }

            cooldown = 0.0f;
        }
Exemplo n.º 5
0
        /// <param name="reloadTime">Time to reload the station with a new missile.</param>
        /// <param name="missilePrefab">Missile to spawn.</param>
        /// <param name="launchPoint">Point where the spawned missile will attach to.</param>
        /// <param name="ownShip">Launching object. Used to prevent missile colliding with self.</param>
        public HardpointStation(float reloadTime, AAMissile missilePrefab, Transform launchPoint, Transform ownShip)
        {
            prefab           = missilePrefab;
            this.reloadTime  = reloadTime;
            this.launchPoint = launchPoint;
            this.ownShip     = ownShip;
            cooldown         = 0.0f;

            loadedMissile = CreateMissile(launchPoint);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Automatically reloads missiles based on a cooldown.
        /// </summary>
        /// <param name="deltaTime">Time between frames. Usually Time.DeltaTime.</param>
        /// <returns>True when a missile was spawned on this frame.</returns>
        public bool Update(float deltaTime)
        {
            bool spawnedNewMissle = false;

            if (loadedMissile == null)
            {
                cooldown -= deltaTime;

                // Finished reloading, spawn new missile.
                if (cooldown <= 0.0f)
                {
                    loadedMissile    = CreateMissile(launchPoint);
                    spawnedNewMissle = true;
                }
            }

            return(spawnedNewMissle);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Spawns a missile on a station.
        /// </summary>
        /// <param name="newParent">Point where the missile will be attached to.</param>
        /// <returns></returns>
        private AAMissile CreateMissile(Transform newParent)
        {
            AAMissile mis = Instantiate(prefab, newParent);

            mis.ownShip = ownShip;

            // Attach the missile to the hardpoint by its attach point if possible.
            if (mis.attachPoint != null)
            {
                mis.transform.localPosition    = -mis.attachPoint.localPosition;
                mis.transform.localEulerAngles = -mis.attachPoint.localEulerAngles;
            }
            else
            {
                mis.transform.localPosition    = Vector3.zero;
                mis.transform.localEulerAngles = Vector3.zero;
            }

            return(mis);
        }