Spawn Limit for enemies

Can someone please give me a script that will limit the enemies being spawned to 50 so i will have 50 enemies on my screen and if i have 49 then one will spawn. I already have a script that spawns enemies i only need a script that kills them and limits them to only 50 on 1 screen.

(=

All you really have to do is in your enemy script when you make then enemy die based on health or whatever spawn another.

Update()
{
  if(health <= 0)
  {
    enemycount--;
    SpawnNewEnemy();
    Destroy(this.gameObject);
    enemycount++;
  }

}

If you want to limit to 50 and you are managing them all from 1 script then you might want to either have a counter or store them in an array. Keep it under 50 by checking the size vs 50.

I would do it via array for management purposes.

var enemies : Array;
var enemyPrefab : GameObject;

function Start()
{
  enemies = new Array();
}
function SpawnNewEnemy()
{
  if(enemies.length >= 50)
  {
    return;
  }

  var newEnemy = Instantiate(enemyPrefab, Vector3(0,0,0), Quaternion.identity);
  enemies.Add(newEnemy);

}