Hi
Got this script which I’ve been working on for a while now. With the help of the community I’ve got it working and ready. The script is an game controller script that controls and changes enemy states. Only problem is that I get the error Array index is out of range.
var alert : boolean;
var caution : boolean;
var normal : boolean;
var alertTimer : float;
var cautionTimer : float;
var alertTime : float = 30;
var cautionTime : float = 30;
//CHASING
var statusGUI : UI.Text;
var guardSpawn : Transform;
//var enemy : GameObject;
var enemyUnit : GameObject[];
var enemyAIScript : EnemyAI[];
var enemyHuntScript : EnemyHunt[];
function Start(){
enemyUnit = GameObject.FindGameObjectsWithTag("Enemy");
for(var i : int = 0; i < enemyUnit.Length; i++)
{
enemyAIScript _= enemyUnit*.GetComponent.<EnemyAI>();*_
enemyHuntScript = enemyUnit*.GetComponent.();*
}
//
alert = false;
caution = false;
normal = true;
}
function Update(){
if(alert == true){
if(alertTimer >= 0){
print(“alert”);
statusGUI.text = "ALERT : "+alertTimer;
alertTimer -= Time.deltaTime;
enemyHuntScript.enabled = true;
enemyAIScript.enabled = false;
}else{
//ALERT FINISHED
//SWITCH TO CAUTION
ActivateCaution();
print(“CAUTION”);
statusGUI.text = “”;
}
}
//CAUTION
if(caution == true){
if(cautionTimer >= 0){
print(“CAUTION”);
statusGUI.text = "CAUTION : "+cautionTimer;
cautionTimer -= Time.deltaTime;
}else{
//
alert = false;
caution = false;
normal = true;
statusGUI.guiText.text = “”;
}
}
//NORMAL
if(normal == true){
alert = false;
caution = false;
print(“Normal”);
alertTimer = 30;
cautionTimer = 30;
statusGUI.text = “NORMAL”;
for(var a : int = 0; a < enemyAIScript.Length; a++)
{
enemyAIScript[a].enabled = true;
}
for(var b : int = 0; b < enemyHuntScript.length; b++){
enemyHuntScript**.enabled = false;**
}
}
}
function Alert(){
statusGUI.text = "ALERT : "+alertTimer;
alertTimer -= Time.deltaTime;
for(var i : int = 0; i < enemyAIScript.Length; i++)
{
enemyAIScript*.enabled = true;*
}
for(var o: int = 0; o < enemyHuntScript.Length; i++)
{
enemyHuntScript[o].enabled = true;
}
}
function ActivateAlert(){
alert = true;
alertTimer = alertTime;
caution = false;
normal = false;
}
function ActivateCaution(){
caution = true;
cautionTimer = cautionTime;
alert = false;
normal = false;
}
Heres the exact error
IndexOutOfRangeException: Array index is out of range.
(wrapper stelemref) object:stelemref (object,intptr,object)
ControlAI.Start () (at Assets/BLAM/Enemies/RegularUnits/ControlAI.js:20)
Thanks Stealth