aboutsummaryrefslogtreecommitdiff
path: root/td/Assets/Scripts/Enemy.cs
diff options
context:
space:
mode:
authorJakob Stendahl <JakobS1n@users.noreply.github.com>2017-10-14 23:17:09 +0200
committerGitHub <noreply@github.com>2017-10-14 23:17:09 +0200
commit8b2c937959c99ab2dfbc3eaf9dc5b9c18cf73371 (patch)
treeb775b07054de58f83cd9df41bf43e61b3facfad1 /td/Assets/Scripts/Enemy.cs
parent76cf99ade6530bdad81088295fb4cf73f5c5b118 (diff)
parentabe835d1112e4804ce63b7d2fa85f8bd76e3c237 (diff)
downloadTD-8b2c937959c99ab2dfbc3eaf9dc5b9c18cf73371.tar.gz
TD-8b2c937959c99ab2dfbc3eaf9dc5b9c18cf73371.zip
Merge pull request #4 from JakobS1n/GUI
Gui
Diffstat (limited to 'td/Assets/Scripts/Enemy.cs')
-rw-r--r--td/Assets/Scripts/Enemy.cs51
1 files changed, 26 insertions, 25 deletions
diff --git a/td/Assets/Scripts/Enemy.cs b/td/Assets/Scripts/Enemy.cs
index 7273370..4d15b64 100644
--- a/td/Assets/Scripts/Enemy.cs
+++ b/td/Assets/Scripts/Enemy.cs
@@ -1,38 +1,39 @@
-using System.Collections;
-using System.Collections.Generic;
+using System.Collections.Generic;
using UnityEngine;
public class Enemy : MonoBehaviour {
+ /* This is a general class that contains an enemy,
+ * Currently it follows the pathway, and dies when reacing the end */
- public float speed;
- public float initialHp;
- public Transform pathWay;
+ [Header("Attributes")]
+ public float Speed; // Speed multiplier
+ public int InitialHp; // HealthPoints
+ public int Damage;
+ public List<Vector3> Waypoints; // Pathway waypoints, should be set by the spawner
+
+ [Header("Scripting vars")]
+ public Player Player; // Reference to the player object, should be set when instantiating
- List<Vector3> waypoints = new List<Vector3>();
- Vector3 waypointPos;
- int waypointNum = -1; // Using minus one so that first addition returns 0, first element in array
-
- void Start () {
- foreach (Transform child in pathWay) {
- waypoints.Add (child.position);
- }
- }
+ private Vector3 _waypointPos; // Current waypoint position
+ private int _waypointNum = -1; // Using minus one so that first addition returns 0, first element in array
void Update () {
- updateWaypoint ();
+ if (Player.GameIsPaused()) { return; } // This ensures that the game stays paused
+
+ if ( (transform.position == _waypointPos && _waypointNum + 1 < Waypoints.Count) || _waypointNum == -1) {
+ _waypointNum++;
+ _waypointPos = new Vector3 (Waypoints [_waypointNum].x, 0.483f, Waypoints [_waypointNum].z);
+ }
- float transformStep = speed * Time.deltaTime;
- transform.position = Vector3.MoveTowards (transform.position, waypointPos, transformStep);
+ float transformStep = Speed * Time.deltaTime;
+ transform.position = Vector3.MoveTowards (transform.position, _waypointPos, transformStep);
- if (waypointNum == waypoints.Count - 1) {
+ // Selfdestruct if object reached the end
+ if (_waypointNum + 1 >= Waypoints.Count) {
+ WaveSpawner.EnemiesAlive--;
+ Player.DecreaseHealth (Damage);
Destroy (gameObject);
- }
- }
-
- void updateWaypoint() {
- if ( (transform.position == waypointPos && waypointNum < waypoints.Count - 1) || waypointNum == -1) {
- waypointNum++;
- waypointPos = new Vector3 (waypoints [waypointNum].x, 0.604f, waypoints [waypointNum].z);
+ return;
}
}