Looking for an error in my code. Im trying to random summon 3 types of enemys, and it keeps summoning unrecorded guys. by the time i killed them all at level 5 it failed to summon the boss because my enemys remaining counter was at -12 i was watching and it kept summoning an extra guy every now and then. when my enemys die they should and look like they are subrtacting 1 from eremaining, and adding 1 to summon. cant figgure out where the extra unrecorded summons are coming from.
Declaration of varriables
public Transform espell;
public Transform emelee;
public Transform eranged;
public Transform ERBoss;
static public int CURLEVEL = 1;
static public int EREMAINING = 0;
static public int summon;
static float EnemySpell = 0;
static float EnemyMelee = 0;
static float EnemyRanged = 0;
static public int Boss = 5;
static public bool BossAlive = false;
static public float KillCount = 0;
static public float TempKillCount = 0;
Code for summoning
if (CURLEVEL < Boss)
{
if (TempKillCount >= CURLEVEL * 2)
{
TempKillCount = TempKillCount - (CURLEVEL * 2);
CURLEVEL += 1;
summon += 1;
}
// Summon New Enemys
while (summon > 0)
{
float lu = Random.Range(1, 100);
if (lu < 13)
{ ESPEED += .25f; }
else if ((lu > 12) && (lu < 26))
{ EROTATION += .05f; }
else if ((lu > 25) && (lu < 51))
{ EnemySpell += 1; }
else if ((lu > 50) && (lu < 76))
{ EnemyRanged += 1; }
else if (lu > 75)
{ EnemyMelee += 1; }
if (EnemySpell <= 0 & EnemyMelee <= 0 & EnemyRanged <= 0)
{ EnemySpell += 1; }
summon -= 1;
}
if (EnemySpell > 0)
{
Vector3 position = new Vector3(Random.Range(-18, 18), 1, Random.Range(-18, 18));
Instantiate(espell, position, Quaternion.identity);
EnemySpell -= 1;
EREMAINING += 1;
}
if (EnemyMelee > 0)
{
Vector3 position2 = new Vector3(Random.Range(-18, 18), 1, Random.Range(-18, 18));
Instantiate(emelee, position2, Quaternion.identity);
EnemyMelee -= 1;
EREMAINING += 1;
}
if (EnemyRanged > 0)
{
Vector3 position3 = new Vector3(Random.Range(-18, 18), 1, Random.Range(-18, 18));
Instantiate(eranged, position3, Quaternion.identity);
EnemyRanged -= 1;
EREMAINING += 1;
}
}
if (CURLEVEL >= Boss && EREMAINING == 0 && BossAlive == false)
{
Debug.Log(Boss + " Boss has almost been summoned");
Vector3 ERB = new Vector3(11, 4, -9);
Instantiate(ERBoss, ERB, Quaternion.identity);
BossAlive = true;
Debug.Log(Boss + " Boss has been summoned");
}
if (CURLEVEL >= Boss && EREMAINING != 0 && BossAlive == false)
{
Debug.Log(" Boss Summon Fail... EREMAINING = " + EREMAINING);
}
Death code for my enemys:
//Out of life
if (curhp < 1 || dead == true)
{
Level.EREMAINING -= 1;
Level.summon += 1;
Level.KillCount += 1;
Level.TempKillCount += 1;
MainCharacter.SCORE += 124;
MainCharacter.CURXP += 20;
Instantiate(explosion, gameObject.transform.position, Quaternion.identity);
Destroy(gameObject);
}