So, I ran into an issue when testing out whether I could die and respawn at the respawnPoint. It seems that the dialogue is no longer triggering AggroGroup to activate the fighter and combat target scripts to reactivate.
Now, I made some (likely bodgy) changes to the script to detect whether an enemy has taken damage (likely from an ability) and if so, they should reactivate and fight the player. Now, this is mostly working as intended, however it’ll only affect targets damaged (by design) and not factor in things like the shoutDistance to aggro other nearby guards.
using UnityEngine;
using RPG.Attributes;
namespace RPG.Combat
{
public class AggroGroup : MonoBehaviour
{
[SerializeField] Fighter[] fighters;
[SerializeField] bool activateOnStart = false;
void Update()
{
Activate(activateOnStart);
}
public void Activate(bool shouldActivate)
{
foreach (Fighter fighter in fighters)
{
CombatTarget target = fighter.GetComponent<CombatTarget>();
Health targetHealth = fighter.GetComponent<Health>();
if (target != null)
{
if (targetHealth.TakenDamage())
{
target.enabled = true;
}
else
{
target.enabled = shouldActivate;
}
}
if (targetHealth.TakenDamage())
{
fighter.enabled = true;
}
else
{
fighter.enabled = shouldActivate;
}
}
}
}
}
Now, the issue seems to be stemming from changing
void Start()
{
Activate(activateOnStart);
}
into: - EDIT: I now see the error here, as noted below.
void Update()
{
Activate(activateOnStart);
}
So that TakenDamage() can be checked. I’ll post that function below:
public bool TakenDamage()
{
if (healthPoints.value < GetInitialHealth())
{
return true;
}
return false;
}
I know I’ve asked a lot of questions lately, but this one has me stumped. Is there a better way to reactivate the guards if they’ve taken damage?
Thanks in advance,
Mark.