From 69a6cc2555d8dfc8314a08e6cef6b67fa1177bf0 Mon Sep 17 00:00:00 2001 From: Jakob Stendahl Date: Sat, 7 Oct 2017 21:16:23 +0200 Subject: Made projectiles, and working health system --- td/Assets/Scripts/tower.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'td/Assets/Scripts/tower.cs') diff --git a/td/Assets/Scripts/tower.cs b/td/Assets/Scripts/tower.cs index 0c812b2..bc8241c 100644 --- a/td/Assets/Scripts/tower.cs +++ b/td/Assets/Scripts/tower.cs @@ -10,6 +10,8 @@ public class tower : MonoBehaviour { public float turnSpeed; // How fast the turret should rotate. Set in designer (tower prefab) [Range(0, 10)] public float towerRange; // How large the range of the tower is. this is the diameter. Set in designer (tower prefab) + public GameObject projectilePrefab; + public Transform firePoint; [Header("Materials")] public Material materialDanger; // The material used when tower can't be placed, set in the designer (tower prefab) public Material materialSuccess; // The material used when the tower can be placed, or is selected, set in the designer (tower prefab) @@ -83,6 +85,7 @@ public class tower : MonoBehaviour { if (fireCountdown <= 0f) { // FAIAAAAA + shoot(); fireCountdown = 1f / fireRate; } @@ -91,6 +94,15 @@ public class tower : MonoBehaviour { } + void shoot() { + GameObject projectileGo = (GameObject) Instantiate (projectilePrefab, firePoint.position, firePoint.rotation); + projectile Projectile = projectileGo.GetComponent (); + if (Projectile != null) { + Projectile.player = player; + Projectile.seek (target); + } + } + void updateTarget() { /* Method that updates the currentTarget. * The target will be set to the nearest in range */ @@ -107,7 +119,6 @@ public class tower : MonoBehaviour { } if (nearestEnemy != null && shortestDistance <= towerRange) { - Debug.Log ("Target aquired"); target = nearestEnemy.transform; } else { target = null; -- cgit v1.2.3