Hi. I just thought I’d try a challenge here to set up a game over and victory conditions if all the units were killed or all the enemies were killed.
I found the enemy list a little more challenging as not all enemies are active at all times.
In LevelScripting.cs I’ve added a Get and Set if the last hider was shown. So if the last hider was deactivated and the last enemy is killed then the game goes to the next scene.
It works but I’m just asking if that would be a decent way to achieve that or can you provide any better solutions.
// LevelScripting.cs
door2.OnDoorOpened += (object sender, EventArgs e) =>
{ //TODO set here?
lastSection = true;
SetActiveGameObjectList(hider3List, false);
SetActiveGameObjectList(enemy2List, true);
};
}
// same code as Hugo's for all the other functions
public bool GetGotToTheLastSection()
{
return lastSection;
}
public void SetGotToTheLastSection(bool lastSection)
{
this.lastSection = lastSection;
}
and then in UnitManager
if (unit.IsEnemy())
{
enemyUnitList.Remove(unit);
if (AreAllUnitsDead(enemyUnitList))
{
if (levelScripting.GetGotToTheLastSection())
{
GameManager.Instance.LoadNextScene();
levelScripting.SetGotToTheLastSection(false);
}
}
}
else
{
friendlyUnitList.Remove(unit);
if (AreAllUnitsDead(friendlyUnitList))
{
GameManager.Instance.LoadGameOverScene();
}
}