diff options
Diffstat (limited to 'td/Assets/Scripts/tower.cs')
-rw-r--r-- | td/Assets/Scripts/tower.cs | 13 |
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; |