aboutsummaryrefslogtreecommitdiff
path: root/td/Assets/Scripts/tower.cs
diff options
context:
space:
mode:
authorJakob Stendahl <jakob.stendahl@outlook.com>2017-10-07 21:16:23 +0200
committerJakob Stendahl <jakob.stendahl@outlook.com>2017-10-07 21:16:23 +0200
commit69a6cc2555d8dfc8314a08e6cef6b67fa1177bf0 (patch)
treebe48ae23e1085c2522808af2d418c852998a8c58 /td/Assets/Scripts/tower.cs
parente13fd4cf1fc0ad9eff857295fd5abc15ab01462c (diff)
downloadTD-69a6cc2555d8dfc8314a08e6cef6b67fa1177bf0.tar.gz
TD-69a6cc2555d8dfc8314a08e6cef6b67fa1177bf0.zip
Made projectiles, and working health system
Diffstat (limited to 'td/Assets/Scripts/tower.cs')
-rw-r--r--td/Assets/Scripts/tower.cs13
1 files changed, 12 insertions, 1 deletions
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 <projectile>();
+ 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;