CanAttack

I had a mind to destory gameobject (enemy) or More specific whatever health component.

    private void Die()
    {
        if(isDead) { return; }
        GetComponent<Animator>().SetTrigger("die");
        isDead = true;

---------> Destory(gameObject, timeToShowDyingMethod); //[SerializeField]
---------> Here I would call a method to drop items if desired
----------> ShowDyingMethod(); <— method to drop items or animate or particle effect, or sound effect…
}

Would this approach get me mixed up later in course?

Also I have another question about the CanAttack() procedure
Something about htis simply does NOT look right?
public bool CanAttack(CombatTarget combatTarget)
{
if(combatTarget == null) { return false; }
Health targetToTest = combatTarget.GetComponent();
return targetToTest != null && !targetToTest.IsDead();
}
-----> seems to me we are already going to return false if targetToTest is null…
-----> aren’t we testing twice? once not needed?

Please explain
Thanks

It would, actually, as the SavingSystem wouldn’t have a hook into the character that has been destroyed. This would mean that if you killed an enemy, saved the game, then loaded the game (via restart, not the L)oad key), the enemy would be alive and back in it’s starting condition.

It isn’t redundant if the game designer made a mistake and forgot to put a Health component on the target. We know that combatTarget is not null, but we don’t know the state of targetToTest until it’s checked.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms