Checfk if all keys have been collected in LevelEndTriggerVolume

This commit is contained in:
baz 2024-03-11 22:04:35 +00:00
parent cffef34d9b
commit 9dc2fff2ed
3 changed files with 28 additions and 8 deletions

View File

@ -24,16 +24,20 @@ void ALevelEndTriggerVolume::OnOverlapBegin(UPrimitiveComponent* OverlappedCompo
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult)
{
// TODO: Add extra functionality!
if (Cast<APlayerCharacter>(OtherActor))
UNakatomiGameInstance* gameInstance = Cast<UNakatomiGameInstance>(UGameplayStatics::GetGameInstance(GetWorld()));
if (gameInstance)
{
GetCollisionComponent()->OnComponentBeginOverlap.Clear();
int CollectedLevelKeysCount = gameInstance->GetCurrentLevelManager()->GetCollectedLevelKeysCount();
int InitialLevelKeysCount = gameInstance->GetCurrentLevelManager()->GetInitialLevelKeysCount();
if (auto gameInstance = Cast<UNakatomiGameInstance>(UGameplayStatics::GetGameInstance(GetWorld())))
// TODO: Add extra checks!
if (Cast<APlayerCharacter>(OtherActor) && CollectedLevelKeysCount == InitialLevelKeysCount)
{
GetCollisionComponent()->OnComponentBeginOverlap.Clear();
gameInstance->GetCurrentLevelManager()->LoadNextLevel();
this->Destroy();
}
this->Destroy();
}
}

View File

@ -29,10 +29,20 @@ void UNakatomiLevelManager::LoadNextLevel()
void UNakatomiLevelManager::IncrementInitialLevelKeys()
{
LevelKeys++;
InitialLevelKeys++;
}
void UNakatomiLevelManager::IncrementCollectedLevelKeys()
{
CollectedLevelKeys++;
}
int UNakatomiLevelManager::GetInitialLevelKeysCount()
{
return InitialLevelKeys;
}
int UNakatomiLevelManager::GetCollectedLevelKeysCount()
{
return CollectedLevelKeys;
}

View File

@ -19,7 +19,7 @@ private:
UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true"))
TSoftObjectPtr<UWorld> NextLevel;
int LevelKeys = 0;
int InitialLevelKeys = 0;
int CollectedLevelKeys = 0;
@ -32,6 +32,12 @@ public:
UFUNCTION()
void IncrementCollectedLevelKeys();
UFUNCTION()
int GetInitialLevelKeysCount();
UFUNCTION()
int GetCollectedLevelKeysCount();
private: