health var updates correctly on client when hit by projectile

This commit is contained in:
2026-01-01 19:35:48 -05:00
parent ecd15c271f
commit 4662e6701a
4 changed files with 63 additions and 8 deletions

View File

@@ -9,6 +9,7 @@ UDDIHealth::UDDIHealth()
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = true;
SetIsReplicatedByDefault(true);
MaxHealth = 0;
CurrentHealth = 0;
ClassName = ClassNames::Scout;
@@ -41,7 +42,7 @@ void UDDIHealth::BeginPlay()
MaxHealth += seg;
CurrentHealth = MaxHealth;
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Cyan, FString::Printf(TEXT("CurrentHealth: %d"), CurrentHealth));
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Emerald, FString::Printf(TEXT("CurrentHealth: %d"), CurrentHealth));
}
@@ -81,10 +82,9 @@ void UDDIHealth::Heal()
// Called to cause damage
void UDDIHealth::TakeDamage(int DamageValue)
{
// if (HealTimer.IsValid())
// HealTimer.Invalidate();
GetWorld()->GetTimerManager().ClearTimer(HealTimer);
CurrentHealth -= DamageValue;
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Cyan, FString::Printf(TEXT("Client Hit\nHealth: %d"), CurrentHealth));
}