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 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”;
enemyAIScript.enabled = true;
enemyHuntScript.enabled = false;
}
}
Sorry if the title is mucked up. It’s kinda hard to explain my problem. Basically I’m making a stealth game. All the enemies have three states controlled by a manager. The manager the script above attached to it. On start up it finds all the gameObjects with the tag enemy. It sorts through them in the for loop and enemyAIScript and enemyHuntScript are assigned to each enemyUnit index. enemyAIScript is the script used for enemies while in the normal and caution phase and enemyHuntScript is the script used for enemies while in the alert phase.
When in alert I want the enemyHuntScript activated for all enemies in the enemyUnit array - And vice versa with enemyAIScript and normal.
Heres the problem though. When Alert is activated only one of the enemyUnits has the enemyHuntScript activated. The others need to have theirs activated manually through the editor. And its the same story when in normal phase. Only the first element has the enemyAIScript activated and the others need theirs activated through editor.
I’m a programming noob and I wont shy away from the fact that I probably messed up somewhere in the for loops. Anyone know how to fix it so all the elements get the script activated not just element 1?
Thanks in advance
Stealth