From da2d66ed82bec696e2d759fc1e9215fabea07ce3 Mon Sep 17 00:00:00 2001 From: Jakob Stendahl Date: Fri, 29 Sep 2017 17:07:07 +0200 Subject: Minor design tweaks --- td/Assets/Prefabs/Path straigth.prefab | Bin 9096 -> 9096 bytes td/Assets/Prefabs/Path turn.prefab | Bin 10392 -> 10392 bytes td/Assets/Scripts/Enemy.cs | 11 ++--------- 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 index 758af59..cb8cac2 100644 Binary files a/td/Assets/Prefabs/Path straigth.prefab and b/td/Assets/Prefabs/Path straigth.prefab differ diff --git a/td/Assets/Prefabs/Path turn.prefab b/td/Assets/Prefabs/Path turn.prefab index 62e392e..fc78ac9 100644 Binary files a/td/Assets/Prefabs/Path turn.prefab and b/td/Assets/Prefabs/Path turn.prefab differ 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 waypoints; - List waypoints = new List(); 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 waypoints = new List(); 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 ().pathWay = pathWay; - newEnemy.GetComponent ().speed = Random.Range (0.3f, 1.2f); + Enemy script = newEnemy.GetComponent (); + Transform transform = newEnemy.GetComponent (); + + script.waypoints = waypoints; + script.speed = Random.Range (0.3f, 1.2f); + transform.position = new Vector3 (0.93f, 0.483f, 0f); } + } } -- cgit v1.2.3