How to Create a Tower Defense Game in Unity – Part 1

Did you make sure that you added a Box2D Collider and that the shape of the collider really covers the whole area of the x that should be clickable? This is the most common error when it comes to implementing clicks on Unity.

Thank you for this great tutorial.
Fantastic

Yust a tip for other readers: do not forget to “deactivate” //public GameObject testEnemyPrefab; and //Instantiate(testEnemyPrefab).GetComponent().waypoints = waypoints;
in “SpawnEnemy” when you begin with part 2.

regards marc

Hi! Thank you for this great tutorial,
I’ve learned a lot from here. I was wondering if how do I convert this into an Android App?

Thanks!
codesofdave.github.io

Hello Barbara,

First many thanks for this great tutoriel…It was superb. I guess you made a big effort to provide us with such a masterpiece tutoriel.

I’m actually facing a major error in MoveMonster.cs that prevents me from going further which is “IndexOutofrangeException” after investigation i found out that this line "Vector3 startPosition = waypoints[currentWaypoint].transform.position;" was the cause of the error.

At first place i thought that Waypoint[] was empty but after adding some Debug.log instrucations to see the content of the waypoints i found that the values were Ok. And Yet the error still persisting.

Could please help me on that matter?!

Thanks

Hi,

I wanted to share my experience too. I tried this tutorial Isometric Tower Defense Wizard Tower - Design Video of Isometric Building - YouTube a tower defense game and basically a step by step from design of theme and characters.

Hi,
I’ve been trying to make the openspot shows up something like a box with another towers/monsters options but i just can’t make it, is it possible to be done with OnMouseUp? The anwser being yes or no, how do i make it?
btw, great tutorial, helped a lot, and sorry for my english.

@davilp It is definitely possible. What you should do is:

  • Create the box you want to show. This can be either a ui object or a component in the game scene. Just remember that if you use a ui object, you need to transform between the ui coordinate system and the game coordinate system.
  • In the OnMouseUp method set the position of the box and make it visible.
  • When the user selected a specific tower in the box, dismiss the box and create a tower on the selected open spot.

How did you make the monster prefab…can u make it specifically…i cant get it…i want to create my own…

@m43kt1s4n What do you mean by you can’t get the monster prefab? Regardless, creating your own enemies prefab requires a few steps:

  • Create an new Game Object and name it however you want, for exampe MySuperCoolEnemy
  • Add a sprite object as a child to the Game Object and select a graphic for it and name it sprite
  • Add two more sprites one for the empty healthbar and one for the full health bar
  • Add the HealthBar script and an Audio Effect to the full health bar. And set some max health. Set CurrentHealth to the same value as max health.

Now follow all the steps in the tutorial on how to add the MoveEnemy script, the Rigidbody 2D, Box Collider 2D and Audio Source.

Hope that helped :slight_smile:

Try also this Space_Gecko - Portfolio | GraphicRiver and the tutorials https://youtu.be/UA7cz3stSn4

When I finished the tutorial, I had the same exact problem-
my enemy wasn’t showing up, I had no idea why.
I tried both "gebirgsbaerbel"s and "goldregin"s solution above.

but a different place was the problem for me.
I forgot the last line of the tutorial, after switching back to unity.
“Select Road in the Hierarchy and set its Test Enemy to the Enemy prefab.”

Great tutorial!!!

Being absolutely green to Unity I learned quite a bit. I’ve completed the full tutorial including Part 2 and enjoy the fruits of my labor and your teaching.

One question … how was the Tutorial Screen added? What is it? And What is its purpose?

Okay, I figured out the Tutorial Screen and I’m working on a Canvas. Is there a tutorial on setting up a Canvas: when it is needed, purpose, etc?

Thanks

This tutorial is more than six months old so questions are no longer supported at the moment for it. We will update it as soon as possible. Thank you! :]