Boolean Not Changing

Hey im trying to make the enemycounter inside the enemyspawn script decrement after the deleted bool is true which is found in the enemy script but for some reason it always equals false i dont understand why here’s the code

Spawn.js

import System.Collections.Generic;


var enemies:GameObject[] = new GameObject [1];
private var tempGO:GameObject[] = new GameObject[3]; 
var playerpos:Transform;
var playerY:float;
var enemycounter:int;
var offset:Vector3;
var enemyTypeAllowed:int;
var newPosition : Vector2;
var spawn_position:Vector3;
var timer:float;
var isSpawning:boolean =false;
private var firstWave:int = 4;


private var thisTransform : Transform;
private var offsetY:float = 50;
private var minset:float = 20;
private var spawnedEnemies = new List.<GameObject>();
private var tempEnemyScript = new List.<Enemy> ();
//private var tempEnemyScript : Enemy[] = new Enemy[4];


function Start () {


playerY = playerpos.position.y;
thisTransform = transform;
spawnenemytype(enemies[1],firstWave);

StartCoroutine("CheckForDeleted");

}


function CheckForDeleted(){

yield WaitForSeconds(1);
//tempEnemyScript = new Enemy[spawnedEnemies.Count];

for (var i:int = 0; i<spawnedEnemies.Count; i++){
	//tempEnemyScript = new Enemy[spawnedEnemies.Count];
	tempEnemyScript.Add( spawnedEnemies*.GetComponent("Enemy"));*

_ if (tempEnemyScript*.deleted)_
_
{_
_
Debug.Log(“deleted”);_
_
enemycounter–;_
_
}_
_
else {_
_
Debug.Log(“Active”);_
_
}*_

* }*
*} *

function Update ()
{

offset = new Vector3(0,Random.Range(minset,offsetY),0);

///Debug

//Debug.Log("did it work "+ tempEnemyScript.Count);
Debug.Log("did it work "+ spawnedEnemies.Count);
//Debug.Log("did it work "+ tempGO.Length);

playerY = playerpos.position.y;
timer +=Time.deltaTime;

newPosition = Random.insideUnitCircle * 5;

if (enemycounter == 0 && !isSpawning)
//for ( var i:int = 0; i >=firstWave; i++)
{
* spawnenemytype(enemies[1],firstWave);*
* //CheckForDeleted();*
* timer =0;*

}

}

function spawnenemytype (enemytype:GameObject, amount:int)

{

var spawnLocation:Vector3;
//var count:int = 0;
var temp:int;
isSpawning = true;
//offset = new Vector3(0,Random.Range(minset,offsetY),0);

//while (count < amount)
for ( var i:int = 0; i < amount; i++)
{
* yield WaitForSeconds(1);*

* temp = Random.Range(1,5);*
* //temp = 1;*
* if (temp == 1)*
* {*

* spawnLocation = new Vector3(newPosition.x,playerY+offset.y,0);*
* Debug.Log("Creating enemy number1: " );*
* //temp = Random.Range(1,5);*
* }*

* if (temp == 2)*
* {*

* spawnLocation = new Vector3(newPosition.x,playerY+offset.y,0);*
* Debug.Log("Creating enemy number2: " );*
* //temp = Random.Range(1,5);*
* }*

* if (temp == 3)*
* { *

* spawnLocation = new Vector3(newPosition.x,playerY+offset.y,0);*
* Debug.Log("Creating enemy number3: " );*
* //temp = Random.Range(1,5);*
* }*

* if (temp == 4)*
* {*

* spawnLocation = new Vector3(newPosition.x,playerY+offset.y,0);*
* Debug.Log("Creating enemy number4: " );*
* //temp = Random.Range(1,5);*
* }*

//for ( var i:int = 0; i <=amount: i++)
tempGO = Instantiate(enemytype,spawnLocation,Quaternion.identity);
spawnedEnemies.Add(tempGO*);*

Debug.Log("how many enemies "+spawnedEnemies.Count);
enemycounter++;
//Debug.Log("Creating enemy number4: " + enemycounter );
//Instantiate(enemies[0],new Vector3(newPosition.x,playerY+offset.y,0),transform.rotation);
}

isSpawning = false;

}

Enemy.js
private var hasAppeared:boolean = false;

//private var delete:boolean = false;

var deleted:boolean =true;
function Start () {

Debug.Log(“deleted is false”);

}

function Update () {

if (renderer.isVisible)

* {*

* hasAppeared = true;*
* Debug.Log(“I can see a cube!!”);*

* }*

if (hasAppeared && !renderer.isVisible)
{
Debug.Log(“I cant see a cube!!”);
deleted = true;
hasAppeared = false;
Destroy(this.gameObject);
}

}

/*function OnBecameVisible ()
{
Debug.Log(“I can see a cube!!”);

if (!renderer.isVisible){
Debug.Log(“I cant see a cube!!”);

* //Destroy(this.gameObject);*

}
}
*/

function OnTriggerEnter2D(theCollision : Collider2D){
if(theCollision.gameObject.name == “Player”)
{
deleted = true;
Destroy(this.gameObject);

}

}

You destroy the GameObject to which Enemy.js is attached, which will also destroy that Enemy.js instance. So accessing “deleted” afterwards will not only not work, it is an illegal action.

Instead, just ignore that “deleted” bool: if you destroy Enemy.js, your variable countScript will simply become null; use that instead of the bool.

Also note you are accessing enemy[1] (=the second array entry) instead of enemy[0], not sure if that is your intention.