diff options
author | Jakob Stendahl <JakobS1n@users.noreply.github.com> | 2017-09-29 01:12:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-29 01:12:27 +0200 |
commit | 9a00d03f80eee94c9fe52f832a0127d9375ad375 (patch) | |
tree | 21f20ea46caa33d155effab5a020ad5721d88a66 /td/Assets/Scripts/Enemy.cs | |
parent | 359cebc2b4e156fd3bd87c9a492ac23014ceb5fe (diff) | |
download | TD-9a00d03f80eee94c9fe52f832a0127d9375ad375.tar.gz TD-9a00d03f80eee94c9fe52f832a0127d9375ad375.zip |
Bytt ut eksempel med starten på et Tower Defence spill (#2)
* Startet på TD :)
* Slett tulleprosjekt
* Added enemy as a prefab
* Fiksa stygge skygga
* Fiksa stygge skygga på android
* Tweaked design, cleanup of enemy script
* Made enemy spawner, plus changed enemy color to red
* Added pan and zoom (Pan is ugly still)
* Veit itj ka som e endra :)
Diffstat (limited to 'td/Assets/Scripts/Enemy.cs')
-rw-r--r-- | td/Assets/Scripts/Enemy.cs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/td/Assets/Scripts/Enemy.cs b/td/Assets/Scripts/Enemy.cs new file mode 100644 index 0000000..7273370 --- /dev/null +++ b/td/Assets/Scripts/Enemy.cs @@ -0,0 +1,39 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Enemy : MonoBehaviour { + + public float speed; + public float initialHp; + public Transform pathWay; + + 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); + } + } + + void Update () { + updateWaypoint (); + + float transformStep = speed * Time.deltaTime; + transform.position = Vector3.MoveTowards (transform.position, waypointPos, transformStep); + + if (waypointNum == waypoints.Count - 1) { + 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); + } + } + +} |