A simple 3d tower defense game demo based on Unity3D game engine.
In this tower defense game demo, there will be enemies(rams) spawned from the enemy(left) side's castle gate and head towards the player(right) side's castle gate. Each enemy's movement will follow a certain path and the path will be calculated again if it is not the best one. We players can place towers(ballista) to shoot and kill each enemy with left mouse click.
For each tower, we need certain golds to place and we can only place towers on green tiles except castle area. If an enemy is destroyed by towers, we will gain certain reward golds, if an enemy reaches the player's castle gate, we will lose certain punish golds. When gold amount is less than or equal to 0 then players lose. Additionally, if our placement of a tower will block the path, then that tower cannot be placed down.
I use object pool to manage each enemy's instantiation. For path finding, I use BFS(Breadth-First Search) approach.
Later, I also let each enemy to find the possible optimal path in real time. When blocked by towers or map obstacles, each enemy may go back, generate and follow another possible optimal path.(The gif for this is too large, I just upload it to my personal website)
I use Unity2020.1.1f1 and JetBrain's Rider IDE for this project under Windows 10 environment.
Unity and Unity hub download
archived Unity download
Jetbrains Rider download
-
Download this repo, open(or unzip and open) the Unity3D_Tower-Defense-Game-Demo folder.
-
Open the Unity Hub, from the Home Screen, click Projects to view the Projects tab.
-
To open an existing Unity Project stored on your computer, click the Project name in the Projects tab, or click Open to browse your computer for the Project folder.
-
Note that a Unity Project is a collection of files and directories, rather than just one specific Unity Project file. To open a Project, you must select the main Project folder, rather than a specific file.
-
For this game, just select the Unity3D_Tower-Defense-Game-Demo folder and open this project.
The whole project in Unity contains two main folders, Assets folder and Package folder.
Under Assets folder, there are altogether 7 subfolders:
-
AssetPackages folder: contains 2 subfolders: VoxelCastle and TextMesh Pro, which help us add visual effects to the game demo.
-
Fonts folder: contains 1 font object we use for this game demo.
-
Materials Objects folder: contains 2 materials we use for this game demo. For instance, enemy material and ground material.
-
PostProcessing folder: contains 1 profile object of this game demo which we use to add some post processing effects.
-
Prefabs folder: contains 27 prefabs we use for this game demo. 20 of them are tile prefabs and are store in a TilePrefabs subfolder. Some of them are: tree prefabs, ram prefab, ballista prefab, object pool prefab, bank prefab and so on.
-
Scenes folder: contains 1 main game scene.
-
Scripts folder: contains altogether 12 scripts. 3 scripts are stored in a PathFinding subfolder and are used for enemy objects' BFS path finding approach: PathFinder, Node and GridManager scripts. Some of other scripts are: EnemyMover, TargetLocator, EnemyHealth and so on.