Change ProcessHits to check for HealthComponent instead of class

This commit is contained in:
Louis Hobbs 2023-06-01 02:26:14 +01:00
parent e3649d4752
commit 33eb3f709e
2 changed files with 11 additions and 4 deletions

View File

@ -112,6 +112,15 @@ void AEnemyCharacter::ProcessHits(TArray<FHitResult> hits)
if (Hit.GetActor())
{
if (auto interactableComponent = Hit.GetActor()->GetComponentByClass<UInteractableComponent>())
{
interactableComponent->Interact();
}
if (auto healthComponent = Hit.GetActor()->GetComponentByClass<UHealthComponent>())
{
healthComponent->TakeDamage(Hit.GetActor(), CurrentWeapon->GetWeaponProperties()->WeaponDamage, nullptr, GetController(), this);
}
}
}
}

View File

@ -284,11 +284,9 @@ void APlayerCharacter::ProcessHits(TArray<FHitResult> hits)
interactableComponent->Interact();
}
if (Hit.GetActor()->ActorHasTag("Enemy"))
if (auto healthComponent = Hit.GetActor()->GetComponentByClass<UHealthComponent>())
{
// TODO: Do thing
auto enemy = Cast<AEnemyCharacter>(Hit.GetActor());
enemy->GetHealthComponent()->TakeDamage(Hit.GetActor(), CurrentWeapon->GetWeaponProperties()->WeaponDamage, nullptr, GetController(), this);
healthComponent->TakeDamage(Hit.GetActor(), CurrentWeapon->GetWeaponProperties()->WeaponDamage, nullptr, GetController(), this);
}
}
}