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, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult) const FHitResult& SweepResult)
{ {
// TODO: Add extra functionality! UNakatomiGameInstance* gameInstance = Cast<UNakatomiGameInstance>(UGameplayStatics::GetGameInstance(GetWorld()));
if (Cast<APlayerCharacter>(OtherActor)) if (gameInstance)
{
int CollectedLevelKeysCount = gameInstance->GetCurrentLevelManager()->GetCollectedLevelKeysCount();
int InitialLevelKeysCount = gameInstance->GetCurrentLevelManager()->GetInitialLevelKeysCount();
// TODO: Add extra checks!
if (Cast<APlayerCharacter>(OtherActor) && CollectedLevelKeysCount == InitialLevelKeysCount)
{ {
GetCollisionComponent()->OnComponentBeginOverlap.Clear(); GetCollisionComponent()->OnComponentBeginOverlap.Clear();
if (auto gameInstance = Cast<UNakatomiGameInstance>(UGameplayStatics::GetGameInstance(GetWorld())))
{
gameInstance->GetCurrentLevelManager()->LoadNextLevel(); gameInstance->GetCurrentLevelManager()->LoadNextLevel();
}
this->Destroy(); this->Destroy();
} }
} }
}

View File

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

View File

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