diff options
author | Jakob Stendahl <jakob.stendahl@outlook.com> | 2017-09-29 17:07:07 +0200 |
---|---|---|
committer | Jakob Stendahl <jakob.stendahl@outlook.com> | 2017-09-29 17:07:07 +0200 |
commit | da2d66ed82bec696e2d759fc1e9215fabea07ce3 (patch) | |
tree | ea2cc72fb12e20fba3199b5cba1609e0784d499d | |
parent | 76cf99ade6530bdad81088295fb4cf73f5c5b118 (diff) | |
download | TD-da2d66ed82bec696e2d759fc1e9215fabea07ce3.tar.gz TD-da2d66ed82bec696e2d759fc1e9215fabea07ce3.zip |
Minor design tweaks
-rw-r--r-- | td/Assets/Prefabs/Path straigth.prefab | bin | 9096 -> 9096 bytes | |||
-rw-r--r-- | td/Assets/Prefabs/Path turn.prefab | bin | 10392 -> 10392 bytes | |||
-rw-r--r-- | td/Assets/Scripts/Enemy.cs | 11 | ||||
-rw-r--r-- | td/Assets/Scripts/EnemySpawner.cs | 16 |
4 files changed, 16 insertions, 11 deletions
diff --git a/td/Assets/Prefabs/Path straigth.prefab b/td/Assets/Prefabs/Path straigth.prefab Binary files differindex 758af59..cb8cac2 100644 --- a/td/Assets/Prefabs/Path straigth.prefab +++ b/td/Assets/Prefabs/Path straigth.prefab diff --git a/td/Assets/Prefabs/Path turn.prefab b/td/Assets/Prefabs/Path turn.prefab Binary files differindex 62e392e..fc78ac9 100644 --- a/td/Assets/Prefabs/Path turn.prefab +++ b/td/Assets/Prefabs/Path turn.prefab diff --git a/td/Assets/Scripts/Enemy.cs b/td/Assets/Scripts/Enemy.cs index 7273370..edd9e29 100644 --- a/td/Assets/Scripts/Enemy.cs +++ b/td/Assets/Scripts/Enemy.cs @@ -6,18 +6,11 @@ public class Enemy : MonoBehaviour { public float speed; public float initialHp; - public Transform pathWay; + public List<Vector3> waypoints; - 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 (); @@ -32,7 +25,7 @@ public class Enemy : MonoBehaviour { void updateWaypoint() { if ( (transform.position == waypointPos && waypointNum < waypoints.Count - 1) || waypointNum == -1) { waypointNum++; - waypointPos = new Vector3 (waypoints [waypointNum].x, 0.604f, waypoints [waypointNum].z); + waypointPos = new Vector3 (waypoints [waypointNum].x, 0.483f, waypoints [waypointNum].z); } } diff --git a/td/Assets/Scripts/EnemySpawner.cs b/td/Assets/Scripts/EnemySpawner.cs index eb0dd43..f1eeb84 100644 --- a/td/Assets/Scripts/EnemySpawner.cs +++ b/td/Assets/Scripts/EnemySpawner.cs @@ -7,11 +7,18 @@ public class EnemySpawner : MonoBehaviour { public Enemy enemyPrefab; public Transform pathWay; public Transform gameWorld; + List<Vector3> waypoints = new List<Vector3>(); int wave; int next = 1; int n = 0; + void Awake() { + foreach (Transform child in pathWay) { + waypoints.Add (child.position); + } + } + void Update () { n++; @@ -20,8 +27,13 @@ public class EnemySpawner : MonoBehaviour { next = (int)Random.Range (50, 400); Enemy newEnemy = Instantiate (enemyPrefab, new Vector3(0, 0, 0), Quaternion.identity, gameWorld); - newEnemy.GetComponent <Enemy> ().pathWay = pathWay; - newEnemy.GetComponent <Enemy> ().speed = Random.Range (0.3f, 1.2f); + Enemy script = newEnemy.GetComponent <Enemy> (); + Transform transform = newEnemy.GetComponent <Transform>(); + + script.waypoints = waypoints; + script.speed = Random.Range (0.3f, 1.2f); + transform.position = new Vector3 (0.93f, 0.483f, 0f); } + } } |