Shooting Gallery — Learning to Lose

Sean Duggan
2 min readMay 19, 2024

--

So, in the last article we discussed a win condition, downing 25 aliens. So, how does the player lose? Well, we do have a time limit already implemented (currently upped to 4 minutes). We could also set up a threshold for the enemies who reach the end of the level. We’ll say that if 10 enemies reach the end, or we hit the time limit, the player will lose. I may have to do some tuning to see if both are possible conditions…

Anyhow, I tweaked the UI to show two values for enemy numbers and tweaked both the UIManager and the GameManager to include both values.

[SerializeField] TMP_Text scoreText;
[SerializeField] TMP_Text timeText;
[SerializeField] TMP_Text enemiesRemainingText;
[SerializeField] TMP_Text enemiesEscapedText;
private int _score;
private int _enemiesRemaining;
private int _enemiesEscaped;
[SerializeField] private float _duration = 240f;

[SerializeField] private int _enemiesToKill = 25;
[SerializeField] private int _enemyEscapeThreshold = 10;

I then coded a Loss Condition check and set it to be called when incrementing the number of escape enemies, or on the Update cycle.

private void CheckLossCondition()
{
if (_enemiesEscaped > _enemyEscapeThreshold || _duration <= 0)
{
Debug.Log("You lose");
Debug.Break();
}
}

I should probably code up something a little bit nicer for wins or losses, but my first step was just to get something functional.

--

--