❔ Tower Defense Enemy Movement

Having a problem with line 37....

1
2 using UnityEngine;
3 
4 [RequireComponent(typeof(Enemies))]
5 public class EnemyMovement : MonoBehaviour
6     {
7     //public static Transform [] waypoints;
8     private Transform target;
9 
10    private int wavepointIndex = 0;
11
12    private Enemies enemy;
13    private object waypoints;
14
15    private void Start()
16        {
17        enemy = GetComponent<Enemies>();
18
19        target = (Transform)waypoints;
20        }
21
22    private void Update()
23        {
24        Vector3 dir = target.position - transform.position;
25        transform.Translate(enemy.speed * Time.deltaTime * dir.normalized, Space.World);
26
27        if(Vector3.Distance(transform.position, target.position) <= 0.4f)
28            {
29            GetNextWaypoint();
30            }
31
32        enemy.speed = enemy.startSpeed;
33        }
34
35    private void GetNextWaypoint()
36        {
37        if(wavepointIndex >= Waypoints.- 1)
38            {
39            EndPath();
40            return;
41            }
42        else
43            {
44            wavepointIndex++;
45            target = Waypoints.points [wavepointIndex];
46            }
47        }
48
49    private void EndPath()
50        {
51        PlayerStats.Lives--;
52        WaveSpawner.EnemiesAlive--;
53        Destroy(gameObject);
54        }
55    }
56
Was this page helpful?