/// <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) { base.Launch(target, velocity); // Peek instead of dequeue so that failed launch commands don't cycle the stations. HardpointStation launchingStation = stations.Peek(); if (launchingStation != null) { bool launchSuccessful = launchingStation.Launch(target, velocity); if (launchSuccessful) { if (fireSource != null) { fireSource.Play(); } // Put this station back at the end of the queue after a launch. stations.Dequeue(); stations.Enqueue(launchingStation); missileCount--; } } }
/// <summary> /// Rebuilds the stations queue. /// </summary> private void InitializeStations() { stations.Clear(); spawnedMissiles = 0; // Spawn missiles on each of the launchpoints. // Note that if the missile count is less than launch points, this will cause funniness. foreach (Transform point in launchPoints) { HardpointStation newStation = new HardpointStation(fireDelay, missilePrefabToLaunch, point, ownShip); stations.Enqueue(newStation); spawnedMissiles++; } }