diff options
Diffstat (limited to 'td/Assets/Scripts/Enemy.cs')
-rw-r--r-- | td/Assets/Scripts/Enemy.cs | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/td/Assets/Scripts/Enemy.cs b/td/Assets/Scripts/Enemy.cs index edd9e29..bd64bd5 100644 --- a/td/Assets/Scripts/Enemy.cs +++ b/td/Assets/Scripts/Enemy.cs @@ -12,21 +12,18 @@ public class Enemy : MonoBehaviour { int waypointNum = -1; // Using minus one so that first addition returns 0, first element in array void Update () { - updateWaypoint (); + 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); - if (waypointNum == waypoints.Count - 1) { + // Selfdestruct if object reached the end + if (waypointNum + 1 >= waypoints.Count) { Destroy (gameObject); } } - - void updateWaypoint() { - if ( (transform.position == waypointPos && waypointNum < waypoints.Count - 1) || waypointNum == -1) { - waypointNum++; - waypointPos = new Vector3 (waypoints [waypointNum].x, 0.483f, waypoints [waypointNum].z); - } - } } |