Spawn Point Manager

v1.0

Each Projectile Spawner can have any number of Spawn Points. These are the points where Projectiles will be created.

The SpawnPointManager is a class which handles how each Spawn Point is used.

The default SpawnPointManager simply moves from one Spawn Point to the next sequentially, as shown in the code below. You can create a new class which inherits from this in order to customize how your Spawn Points are selected.

namespace MagicPigGames.Projectiles
{
    [CreateAssetMenu(fileName = "New Sequential Spawn Points", menuName = "Projectile System/Spawn Point Managers/Sequential Spawn Points")]
    [System.Serializable]
    public class SpawnPointManager : ScriptableObject
    {
        public virtual int NextSpawnPointIndex(ProjectileSpawner projectileSpawner, int value = 1)
        {
            if (projectileSpawner.spawnPoints.Count == 0)
                throw new InvalidOperationException("There are no spawn points available.");

            projectileSpawner.SpawnPointIndex += value;
            
            if (projectileSpawner.SpawnPointIndex < 0)
                projectileSpawner.SpawnPointIndex += projectileSpawner.spawnPoints.Count;
            projectileSpawner.SpawnPointIndex %= projectileSpawner.spawnPoints.Count;

            return projectileSpawner.SpawnPointIndex;
        }
    }
}

Your game is unique! And your Spawners are unique as well! Customizing how the Spawn Points are selected is a powerful tool.

Customization Scenario

As an example, perhaps your spawner has multiple spawn positions, and they sequentially fire as in the default SpawnPointManager -- except that each one can be destroyed by the player. As the player destroys them, you may wish to skip over the ones that have been destroyed.

Last updated