Hello! I’ve been playing around in the FPS Microgame and added a boss. I would like the game to end once you beat the boss. You get an Objective script that ends the game after you kill x amount of enemies, but I can’t figure out how to make the game end after you kill just one specific enemy, in this case, the boss. Sorry for the beginner question!
I’m looking into this but, so far, I added a point reach objective as a loot drop assigned to the enemy boss. The problem with this is that the message doesn’t appear until you destroy the enemy boss so I’m looking into how to add a the objective under the GameManager, not sure how to do that yet.
----update------
I did a quick edit of the Kill Enemies script and added a field to assign the boss in the inspector. I started by duplicating the ObjectiveKillEnemies object under GameManager, disabled the objective and added this. There’s a lot of unnecessary code in it but it works for now. I hope it helps!
using Unity.FPS.Game;
using UnityEngine;
namespace Unity.FPS.Gameplay
{
public class ObjectiveKillBoss : Objective
{
[Tooltip("Chose whether you need to kill every enemies or only a minimum amount")]
public bool MustKillAllEnemies = true;
[Tooltip("If MustKillAllEnemies is false, this is the amount of enemy kills required")]
public int KillsToCompleteObjective = 5;
[Tooltip("Start sending notification about remaining enemies when this amount of enemies is left")]
public int NotificationEnemiesRemainingThreshold = 3;
int m_KillTotal;
//assign a boss
[SerializeField] GameObject boss = null;
//protected override
protected override void Start()
{
base.Start();
EventManager.AddListener<EnemyKillEvent>(OnEnemyKilled);
// set a title and description specific for this type of objective, if it hasn't one
if (string.IsNullOrEmpty(Title))
Title = "Eliminate " + (MustKillAllEnemies ? "all the" : KillsToCompleteObjective.ToString()) +
" enemies";
if (string.IsNullOrEmpty(Description))
Description = GetUpdatedCounterAmount();
}
void OnEnemyKilled(EnemyKillEvent evt)
{
if (IsCompleted)
return;
m_KillTotal++;
if (MustKillAllEnemies)
KillsToCompleteObjective = evt.RemainingEnemyCount + m_KillTotal;
int targetRemaining = MustKillAllEnemies ? evt.RemainingEnemyCount : KillsToCompleteObjective - m_KillTotal;
//check if enemy killed is the boss
if (evt.Enemy == boss)
{
targetRemaining = 0;
}
// update the objective text according to how many enemies remain to kill
if (targetRemaining == 0)
{
CompleteObjective(string.Empty, GetUpdatedCounterAmount(), "Objective complete : " + Title);
}
else if (targetRemaining == 1)
{
string notificationText = NotificationEnemiesRemainingThreshold >= targetRemaining
? "One enemy left"
: string.Empty;
UpdateObjective(string.Empty, GetUpdatedCounterAmount(), notificationText);
}
else
{
// create a notification text if needed, if it stays empty, the notification will not be created
string notificationText = NotificationEnemiesRemainingThreshold >= targetRemaining
? targetRemaining + " enemies to kill left"
: string.Empty;
UpdateObjective(string.Empty, GetUpdatedCounterAmount(), notificationText);
}
}
string GetUpdatedCounterAmount()
{
return m_KillTotal + " / " + KillsToCompleteObjective;
}
void OnDestroy()
{
EventManager.RemoveListener<EnemyKillEvent>(OnEnemyKilled);
}
}
}