Hello again Brian. Sorry if I’m asking a lot of questions today, but this death bug is now more frequent than ever, where the player frequently now, although he’s dead, still tries to attack the enemy even if he’s dead, and there’s no way for him to stop (the only way for him to stop is if he’s using melee, and the enemies walk away), and Respawn (Respawning pretty much never happens now…). Any other solutions to this problem? The more the enemies attacking him, the less likely he is to respawn, and this is now becoming a serious problem for my player in-game. This is my current ‘AwardExperience()’ function:
private void AwardExperience(GameObject instigator, Skill skill) {
if (instigator.TryGetComponent(out SkillExperience skillExperience)) {
if (instigator.TryGetComponent(out Health otherHealth) && !otherHealth.IsDead()) {
skillExperience.GainExperience(skill, Mathf.RoundToInt(GetComponent<AIController>().GetXPReward()));
// If you don't want to assign individual XP to your enemies, use the below formula instead (and change them up in 'Progression' attached to each individual enemy):
// skillExperience.GainExperience(skill, Mathf.RoundToInt(GetComponent<BaseStats>().GetStat(Stat.ExperienceReward)));
}
}
}
And this is my ‘TakeDamage()’ function:
public void TakeDamage(GameObject instigator, float damage, Skill skill) {
// Check what type of weapon the player is holding, so the game knows what type of skill to train him up for:
// skill = weaponConfig.CheckForSkill();
print(gameObject.name + " took damage: " + damage);
// This function clamps the health of the player, based on taken damage
// and if the target is dead, we want them to die and give our player some XP
// (using the 'AwardExperience(GameObject instigator)' function)
healthPoints.value = Mathf.Max(healthPoints.value - damage, 0); // Clamps our health value to never go negative, neither above what our player currently has
takeDamage.Invoke(damage); // invoking a 'TakeDamage' event (if our player is not dead),
// so when our player gets hit by an enemy, we want to display
// the text of the damage taken
onTakenHit?.Invoke(instigator); // if you get hit, you automatically fight back!
// when the player dies:
if (healthPoints.value == 0) {
onDie.Invoke(); // Invokes external UnityEvent Audio 'Die', combined with other events, when our Enemy/Player has taken enough damage to die
// AwardExperience(instigator); // (SECOND 'AwardExperience()' FUNCTION) Award experience to whoever won the battle
AwardExperience(instigator, skill); // Award experience to whoever won the battle, for the chosen skill (for the player obviously) that won the battle with (Attack, Defence, Mage or Range)
GetComponent<ActionSchedular>().CancelCurrentAction();
}
// ADDON LINE RIGHT BELOW THIS COMMENT:
// else takeDamage.Invoke(damage);
UpdateState(); // Update the Players' health state
}
Both are in ‘Health.cs’. Any other ways to entirely eliminate the issue?