How to make "if" statement happen only once, until retriggered

Hey, my question isn’t phrased too well, because I didn’t know how to state it in a small amount of words.

I have a “boss” object that spawns when the player obtains 20 points, and again at 40 points, and again at 60 points (etc etc etc) - this functions fine, but there is a small issue in the “points” system I have. If the player kills multiple enemies at the same time (which is very possible, due to a “Kill Everything on Map Special Ability” the score instantly goes from 19, to 21 - which skips the boss phase entirely.

I understand that if I just add “bossTriggered = false” command, and change the if statement to say 20 points or above - I could make sure it always spawned, but then later (20 points later) I want to be able to spawn the boss again, which is were I’m running into the issue.

I will paste the code below.

using UnityEngine;
using System.Collections;

public class bossSpawner : MonoBehaviour {

    public GameObject bossOne;
    public GameObject bossSpawn;
    public GameObject scoreTimer;
    public int spawnBoss;
    //public int onlyMakeOne;
    score myScore;

	void Start () {
        spawnBoss = 20;
        GameObject scoreTimer = GameObject.Find("scoreTimer");
        myScore = scoreTimer.GetComponent<score>();
	}
	
	void Update () {

        if (myScore.scoreme == spawnBoss)
        {
            Instantiate (bossOne, bossSpawn.transform.position, bossSpawn.transform.rotation);
            spawnBoss = spawnBoss + 20;
        }

	}
}

could anyone tell me if there is a good way to do this?

The only solutions I can think of, have potential other errors attached to them (example, adding a “bossTriggered = true” bool, then setting it back to false a few points before the next boss, but my player can skip upwards of 10 points at a time, so this could still have major issues.

@Fingerlights I would add a new int called waveScore right under myScore, and whenever your player gets a point add points to both but keep them separate. I call it waveScore because the difficulty comes in waves but you could call it whatever you like.

Then in your update you would check if waveScore is larger than spawnBoss and if it is, subtract the amount that spawnBoss is (in this case 20) (and of course spawn your boss). If you do it like that you are not effecting the overall score but you are creating a loop that could go on forever. Even if waveScore was 21 when it hits that if statement, you spawn the boss and subtract 20 from waveScore making it now 1 which sets you up for the next time around.

Could you do something like this?

void Update()
{
    if (myScore.scoreme >= spawnBoss)
    {
        int difference = myScore.scoreme - spawnBoss; // 66 - 20 = 46

        if(difference == 0)
        {
            difference = 1;
        }

        int multiplier = Mathf.CeilToInt(difference / 20); // 46/20 = 2.3 -> ceiling = 3
        int thisBoss = 20 * multiplier; // 20 * 3 = 60          

        Instantiate(bossOne, bossSpawn.transform.position, bossSpawn.transform.rotation);

        spawnBoss += thisBoss; //20 + 60 = 80
    }
}

The comments are just a test case where spawnBoss is the initial value(20) and the score jumps ahead to 66.

You could use the “thisBoss” variable to spawn bosses out of a dictionary of bosses.

@Fingerlights
A simple fix would be to first add a global like so

int bossCount = 0;

and then replace

if (myScore.scoreme == spawnBoss)
{
    Instantiate (bossOne, bossSpawn.transform.position, bossSpawn.transform.rotation);
    spawnBoss = spawnBoss + 20;
}    

with

if (bossCount < (myScore.scoreme / 20)) // this is assuming that myScore.scoreme is an int
{
    bossCount++;
    spawnBoss = spawnBoss + 20;
    Instantiate (bossOne, bossSpawn.transform.position, bossSpawn.transform.rotation);
}