Spawners, Switches, and FireWalls - GameDevStudioUCSD/GardensGrow GitHub Wiki

Both the EnemySpawner and Switch scripts have a type of field called UnityEvent. This is basically a list of methods assigned in the editor that are called from the script. For the Spawner, these methods are called, in order, on the frame that the Spawner dies. For the Switch, they're called whenever it's hit.

The FireWall script has a method called Toggle which disables or enables the wall. To have the Wall be controlled by a Switch, just press the + button on the Switch's event list, drag the FireWall object into its field, and then select the FireWallObject.Toggle() method. It will be called each time the Switch is pressed. To have an EnemySpawner disable the FireWall when it dies, simply do the same on the EnemySpawner object.

Any number of methods can be called by a single UnityEvent. To use a FireWall made of many small fires, simply add each FireWall object individually. Alternatively, the FireWallObject script can be removed from each individual fire, then placed back on a container holding all of the FireWall objects. If this is done, only one method needs to be called. This is the method used for the sample FireWall in the MVP scene.