The DemonManager spawns Demons in the scene.
NOTE: Originally this FSM used Create Object to spawn the demons, but you could see a slight framerate hitch whenever a demon was created. So now the manager pre-spawns all the demons and then activates/deactivates them as necessary.
This is a common design in games, BUT it does make this FSM a more advanced example than I originally intended!
FSM Diagram
States
Events
- repeat - Used to repeat Prespawn Demons until it is finished.
- yes - Used by the Max Demons test.
- no - Used by the Max Demons test.
Variables
- lastCreated - Stores the last created Demon so we can manipulate it.
- maxDemons - The maximum number of allowed demons in the scene. This is manipulated by the Director FSM.
- numDemons - The number of active demons in the scene.
- numSpawnPoints - The number of spawn points it the scene. Discovered by counting the number of children of the SpawnPoints root object.
- spawnDelay - The delay in seconds between spawning demons. This is manipulated by the Director FSM.
- spawnPoint - Stores a reference to a spawn point object.
- spawnPointIndex - Used to find a spawnpoint. See Get Child Num.