For my Scripting 2 Midterm Project, I went a little overboard and designed an entire Tower Defense game from scratch when I was simply supposed to come up with a unique gameplay mechanic. During the summer prior to the semester, I prototyped a full 3D tower defense game in an attempt to learn/work on some different Unity Design Patterns, so this game was an attempt to take what I had learned and translate it to 2D.
The game is simple, visually, and only contains enough effects to make the various towers’ differences plain. The code for this project is available on GitHub, as the structure of the game is more interesting than the game itself.
- Enemy Paths are stored as a List of Transforms; enemies build a path to the home tower upon spawn by working backwards from the home tower Tile to their spawn location; this allows paths to be easily reversed, as in the Bomb Tower that implants a bomb in an enemy and send them walking back towards their spawn point.
- Not many TypeObjects or object pooling here, but the ever-present One-Draw Healthbars and ScriptableObject Events can be found.
- Towers are using Unity Circle Colliders and OnTriggerEnter/Exit functions to maintain a list of valid enemies in range.
- Tower class has an overridable targeting function; default is closest to tower, but the Glue Tower, for example, looks first for enemies without the Glue Status Effect.
- Enemies use TypeObjects for their PerTick() and OnDie() Actions (similar to the EnemyAction system in Dwarf Digger).
- Each EnemyWave is setup via ScriptableObject. When a wave setup matches the current wave number, the system uses its configuration to update the currently used wave setup and the valid Enemy prefabs to spawn can be replaced:
- Further notes available in the below doc:
Leave a Reply