Tower Defense Tutorial – Brackeys – Ep. 13

February 13, 2019

Tower Defense Tutorial

Episode 13 – Lives

Youtube – How to make a Tower Defense Game (E13 LIVES) – Unity Tutorial

By: Brackeys
Ep. 13

We started by adding another public int, Lives, to the playerstats script. We then copied the bottom in-game canvas and pasted it to the top to hold our lives UI text element.

This tutorial involves a lot of references between different scripts. They suggest that if you’re making a larger game with a lot of moving components that you want to optimize, make calls to methods within the other scripts that do the changes locally, as opposed to directly altering the variables from the other script. In this tutorial, they end up just having everything go through the GameManager and having it handle everything locally.

We created a GameManager script for the gameManager object. The first thing we have this doing is handling the game over situation. It checks if lives <= 0, and if so, runs the EndGame method. We also added the standard gameEnded bool just so the check doesn’t run the EndGame method many times.

We then looked at the enemy script to start fleshing out its functionality. We added a health int, as well as methods to deal with receiving damage, TakeDamage, and dying, Die. TakeDamage also receives an int as input to determine how much damage to apply.

Next was filling out the Bullet script. We updated the Damage method so it grabs the Enemy script component of what it hits now and calls the TakeDamage method we added. We also added a damage int to Bullet that we could pass into TakeDamage to control how much health Damage removes.

Finally, we created another particle effect for the death of the enemy objects. This was another simple one copied from our bullet impact effect, we just varied the values a bit and changed the material to that of the enemy to look like the enemy is breaking apart. I also noted some differences in the particle editor over the large difference in Unity versions.

LOCATIONS OF BASIC METHODS

This section will just list some of the small basic methods created, where they are placed, whether they are public/private/etc., and whether they take input variables to help keep track of a framework for creating really simple games.

      Enemy

    • Take Damage(int amount) – Public – Applies damage to the object based on the int input
    • Die() – Private – Performs basic functions when health reaches 0, like destroy gameObject
      Game Manager

    • End Game – Private – performs actions when end game state is reached (i.e. Lives are 0)
      Bullet

    • Damage(Transform enemy) – private – gets the Enemy script component of the transform entered and calls the TakeDamage method, sending with it the damage variable from Bullet

SUMMARY

  • Larger projects may work better by calling internal methods of separate scripts to handle variables locally instead of directly changing the variables from the outside script
  • Make small, separate methods to deal with “EndPaths”. Could look into this terminology more.
  • Unity’s particle creation system has definitely changed over time, so just be aware when doing older tutorials.