Add Kill Counter

This commit is contained in:
baz 2024-08-21 01:28:16 +01:00
parent 1bc85f970a
commit 2ad6b53ab3
4 changed files with 29 additions and 2 deletions

BIN
Content/Widgets/HUD/BP_HUDWidget.uasset (Stored with Git LFS)

Binary file not shown.

View File

@ -3,6 +3,9 @@
#include "EnemyCharacter.h" #include "EnemyCharacter.h"
#include "VampireGameMode.h"
#include "Kismet/GameplayStatics.h"
AEnemyCharacter::AEnemyCharacter(const FObjectInitializer& ObjectInitializer) AEnemyCharacter::AEnemyCharacter(const FObjectInitializer& ObjectInitializer)
{ {
} }
@ -39,5 +42,8 @@ void AEnemyCharacter::OnDeath()
GetWorld()->SpawnActor<AEXPPickup>(EXPPickupTemplate, GetActorLocation(), FRotator::ZeroRotator, GetWorld()->SpawnActor<AEXPPickup>(EXPPickupTemplate, GetActorLocation(), FRotator::ZeroRotator,
actorSpawnParameters); actorSpawnParameters);
AVampireGameMode* gamemode = Cast<AVampireGameMode>(UGameplayStatics::GetGameMode(GetWorld()));
gamemode->IncrementEnemyDeathCount();
//} //}
} }

View File

@ -16,6 +16,11 @@ void AVampireGameMode::BeginPlay()
GetWorldTimerManager().SetTimer(SpawnEnemyTimerDelegate, this, &AVampireGameMode::SpawnEnemy, 1.0f, true); GetWorldTimerManager().SetTimer(SpawnEnemyTimerDelegate, this, &AVampireGameMode::SpawnEnemy, 1.0f, true);
} }
int AVampireGameMode::GetEnemyDeathCount()
{
return EnemyDeathCount;
}
void AVampireGameMode::SpawnEnemy() void AVampireGameMode::SpawnEnemy()
{ {
FVector TopLeft, TopLeftDir; FVector TopLeft, TopLeftDir;
@ -68,3 +73,8 @@ void AVampireGameMode::SpawnEnemy()
Actor->SetActorLocation(SpawnLocation + Direction); Actor->SetActorLocation(SpawnLocation + Direction);
Actor->SpawnDefaultController(); Actor->SpawnDefaultController();
} }
void AVampireGameMode::IncrementEnemyDeathCount()
{
EnemyDeathCount++;
}

View File

@ -28,9 +28,20 @@ private:
FTimerHandle SpawnEnemyTimerDelegate; FTimerHandle SpawnEnemyTimerDelegate;
int EnemyDeathCount = 0;
protected: protected:
virtual void BeginPlay() override; virtual void BeginPlay() override;
public:
UFUNCTION(BlueprintCallable, BlueprintPure)
int GetEnemyDeathCount();
UFUNCTION()
void IncrementEnemyDeathCount();
protected:
UFUNCTION() UFUNCTION()
void SpawnEnemy(); void SpawnEnemy();
}; };