Hello, I am currently following along with a few Tutorial videos and I am currently working on a Tower Defense game that was included in the Project. I am not entirely sure what the conflict is I think it has something to do with the OnTriggerEnter2d function being called because I can manually have my Enemies go to the next CheckPoint by changing the Target int. below is Screenshots of the game and the code I used. I am pretty new to coding and I have searched for a fix but I am stumped. If you can help that would be great Thank you in advance!
EDIT The Issue I am having is my enemy reaches the first checkpoint but he does not move to the next checkpoint he only stays at the first checkpoint
Scene View & Game View
Enemy & Checkpoint Inspector
Enemy Movement Script
public int target = 0;
public Transform exitPoint;
public Transform[] waypoints;
public float navUpdate;
private Transform enemy;
private float navTime = 0;
// Use this for initialization
void Start () {
enemy = GetComponent<Transform>();
}
// Update is called once per frame
void Update () {
if (waypoints != null)
{
navTime += Time.deltaTime;
if (navTime > navUpdate)
{
if (target < waypoints.Length)
{
enemy.position = Vector2.MoveTowards(enemy.position, waypoints[target].position, navTime);
} else
{
enemy.position = Vector2.MoveTowards(enemy.position, exitPoint.position, navTime);
}
navTime = 0;
}
}
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "waypoint")
target += 1;
else if (other.tag == "Finish")
GameManager.instance.RemoveEnemyFromScreen();
Destroy(gameObject);
}
}
GameManager Script
public static GameManager instance = null;
public GameObject[] enemies;
public Transform[] spawnPoint;
public float spawnTime = 1.5f;
public int maxEnemiesOnScreen;
public int totalEnemies;
public int enemiesPerSpawn;
private int enemiesOnScreen = 0;
void Awake()
{
if (instance == null)
instance = this;
else if (instance != this)
Destroy(gameObject);
DontDestroyOnLoad(gameObject);
}
// Use this for initialization
void Start () {
SpawnEnemy();
InvokeRepeating("SpawnEnemy", spawnTime, spawnTime);
}
// Update is called once per frame
void Update () {
}
void FixedUpdate()
{
}
public void SpawnEnemy()
{
if (enemiesPerSpawn > 0 && enemiesOnScreen < totalEnemies)
{
for (int i = 0; i < enemiesPerSpawn; i++)
{
if (enemiesOnScreen < maxEnemiesOnScreen)
{
int spawnIndex = Random.Range(0, spawnPoint.Length);
GameObject newEnemy = Instantiate(enemies[0]) as GameObject;
newEnemy.transform.position = spawnPoint[spawnIndex].position;
enemiesOnScreen += 1;
}
}
}
}
public void RemoveEnemyFromScreen()
{
if (enemiesOnScreen > 0)
{
enemiesOnScreen -= 1;
}
}
}

