- Home /
Question by
Seventh Stealth · Jan 10, 2015 at 07:55 PM ·
javascriptaigetcomponent
GetComponent getting the whole Object instead of a script.
var enemyUnit : GameObject;
var enemyAIScript : EnemyAI;
var enemyHuntScript : EnemyHunt;
function Start(){
enemyUnit = GameObject.FindGameObjectWithTag("Enemy");
enemyAIScript = enemyUnit.GetComponent.<EnemyAI>();
enemyHuntScript = enemyUnit.GetComponent.<EnemyHunt>();
alert = false;
caution = false;
normal = true;
}
function Update(){
if(alert == true && alertTimer >= 0){
caution = false;
normal = false;
statusGUI.guiText.text = "ALERT : "+alertTimer;
alertTimer -= Time.deltaTime;
enemyAIScript.active = false;
enemyHuntScript.active = true;
}
}
When I play in the editor, the line - enemyAIScript.active = false , disables the whole object ir's attached to rather than the script EnemyAI. Any ideas why ? Please help Thanks in advance Stealth
Comment
Best Answer
Answer by tanoshimi · Jan 10, 2015 at 08:03 PM
active
is a (deprecated) property of the GameObject, not of a component. To disable a component, use:
enemyAIScript.enabled = false;
Oh.. Shit. Thanks man you've helped out loads today :D !
Your answer
![](https://koobas.hobune.stream/wayback/20220613180100im_/https://answers.unity.com/themes/thub/images/avi.jpg)