and… nope, didn’t work - if it helps, this is the updated script:
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
using RPG.Movement;
using Unity.VisualScripting;
using RPG.Attributes;
namespace RPG.Combat
{
public class AggroGroup : MonoBehaviour
{
[SerializeField] List<Fighter> fighters = new List<Fighter>(); // fighters to aggregate when our player takes a wrong dialogue turn (and pisses everyone off)
[SerializeField] bool activateOnStart = false;
[SerializeField] bool resetIfPlayerDies = true; // this is left as a boolean because it allows us to choose which aggroGroup members reset their settings on players' death, and which groups may not reset themselves on death (depending on your games' difficulty)
private bool isActivated; // Activates/deactivates the 'aggroGroup'
private bool playerActivated; // this boolean ensures that the group does not give up on trying to fight the player, if the main character dies, ensuring that they still fight him, even without the leader
private Health playerHealth;
private void Start()
{
// Ensures guards are not active to fight you, if you didn't trigger them:
Activate(activateOnStart);
}
private void OnEnable()
{
if (resetIfPlayerDies)
{
playerHealth = GameObject.FindGameObjectWithTag("Player").GetComponent<Health>();
if (playerHealth != null) playerHealth.onDie.AddListener(ResetGroupMembers);
}
}
public void OnDisable()
{
if (resetIfPlayerDies)
{
Health playerHealth = GameObject.FindGameObjectWithTag("Player").GetComponent<Health>();
if (playerHealth != null) playerHealth.onDie.RemoveListener(ResetGroupMembers);
}
}
public void ResetGroupMembers()
{
Activate(false);
}
public void Activate(bool shouldActivate)
{
fighters.RemoveAll(fighter => fighter == null || fighter.IsDestroyed());
foreach (Fighter fighter in fighters)
{
ActivateFighter(fighter, shouldActivate);
}
isActivated = shouldActivate;
}
private void ActivateFighter(Fighter fighter, bool shouldActivate)
{
CombatTarget target = fighter.GetComponent<CombatTarget>();
if (target != null)
{
target.enabled = shouldActivate;
}
fighter.enabled = shouldActivate;
}
public void AddFighterToGroup(Fighter fighter)
{
// If you got the fighter you want to add on your list, return:
if (fighters.Contains(fighter)) return;
// For other fighters on the list, add them lah:
fighters.Add(fighter);
ActivateFighter(fighter, isActivated);
}
public void RemoveFighterFromGroup(Fighter fighter)
{
// Remove fighters from the list
if (fighter == null) return;
ActivateFighter(fighter, false);
fighters.Remove(fighter);
}
}
}