diff options
Diffstat (limited to 'td/Assets/Scripts')
-rw-r--r-- | td/Assets/Scripts/Enemy.cs | 11 | ||||
-rw-r--r-- | td/Assets/Scripts/EnemySpawner.cs | 16 |
2 files changed, 16 insertions, 11 deletions
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); } + } } |