Change ProcessHits to check for HealthComponent instead of class
This commit is contained in:
parent
e3649d4752
commit
33eb3f709e
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue