I have a scene with a few different enemies in it, the scene starts with one enemy active with the others waiting around. I would like the next enemy in the array to come to life when the last enemy gets destroyed. Could anyone help me out with some logic for this situation as I’m a bit stumped at the moment.
I have this so far which keeps my first enemy active while the others are temporarily disabled:
##Edit3##
I’m heading out for a while, this is all the relevant code to the question, if anyone could help me out, i’d greatly appreciate it. I now have the number starting at 0 and increasing to 1 when the ship hits a bullet but, the Debug.Log
in the Update, constantly outputs 0 at the beginning, but when my trigger is activated and the number changes to 1, it only shows it once and then I get nothing from the console when really it should repeat 1 constantly, just in case that’s relevant:
using UnityEngine;
using System.Collections;
public class EnemyAI : MonoBehaviour {
public bool isActive = true;
public int shipCount = 13;
string shipName = "ship";
int num = 0;
void Start()
{
//Sets ship 0 to true, leaving the rest at false
if(gameObject.tag == shipName + num)
{
isActive = true;
}
else
isActive = false;
}
void Update()
{
Debug.Log (shipName + num);
if(gameObject.tag == shipName + num && isActive == false)
{
isActive = true;
}
if(isActive == false)
{
GetComponent<EnemyAI>().enabled = false;
}
else
GetComponent<EnemyAI>().enabled = true;
}
void OnTriggerEnter(Collider collide)
{
if(gameObject.tag == shipName + num && isActive == true)
{
if(collide.gameObject.tag == "bullet")
{
isActive = false;
num++;
}
}
}
}