AdinaS
1
Hello, I try to find all spawned enemies using
var enemies = GameObject.FindGameObjectsWithTag("Enemy");
for( var x in enemies ) {
x.GetComponent(EnemyAI).enemyhealth = 0;
}
But i get this error “Object reference not set to an instance of an object”.
Thanks 
Duugu
2
Hello. Is GameObject set to something? Or applies the error to line 3? Do all enemy objects have an EnemyAI component?
phoda
3
Is that foreach loop (i dont know JS only C#)
but to prevent error you can ask if it is there
add something like this
if ( x.GetComponent(EnemyAI).enemyhealth != null);
x.GetComponent(EnemyAI).enemyhealth=0;
i dont know if its correct but it would be of such format
Kiwasi
4
Chances are you have some objects tagged enemy without an EnemyAI component.
AdinaS
5
No, all enemies are tagged with Enemy and have EnemyAI component. I solved this problem in other way.
Duugu
6
… and the problem/solution was? 
Kiwasi
7
Pineapples. Lots of pineapples.