diff --git a/Source/Nakatomi/LevelEndTriggerVolume.cpp b/Source/Nakatomi/LevelEndTriggerVolume.cpp index caf67e3..9fb2f1f 100644 --- a/Source/Nakatomi/LevelEndTriggerVolume.cpp +++ b/Source/Nakatomi/LevelEndTriggerVolume.cpp @@ -24,16 +24,20 @@ void ALevelEndTriggerVolume::OnOverlapBegin(UPrimitiveComponent* OverlappedCompo UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) { - // TODO: Add extra functionality! - if (Cast(OtherActor)) + UNakatomiGameInstance* gameInstance = Cast(UGameplayStatics::GetGameInstance(GetWorld())); + if (gameInstance) { - GetCollisionComponent()->OnComponentBeginOverlap.Clear(); + int CollectedLevelKeysCount = gameInstance->GetCurrentLevelManager()->GetCollectedLevelKeysCount(); + int InitialLevelKeysCount = gameInstance->GetCurrentLevelManager()->GetInitialLevelKeysCount(); - if (auto gameInstance = Cast(UGameplayStatics::GetGameInstance(GetWorld()))) + // TODO: Add extra checks! + if (Cast(OtherActor) && CollectedLevelKeysCount == InitialLevelKeysCount) { + GetCollisionComponent()->OnComponentBeginOverlap.Clear(); + gameInstance->GetCurrentLevelManager()->LoadNextLevel(); + + this->Destroy(); } - - this->Destroy(); } } diff --git a/Source/Nakatomi/NakatomiLevelManager.cpp b/Source/Nakatomi/NakatomiLevelManager.cpp index 41a8400..6f8a7e8 100644 --- a/Source/Nakatomi/NakatomiLevelManager.cpp +++ b/Source/Nakatomi/NakatomiLevelManager.cpp @@ -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; +} diff --git a/Source/Nakatomi/NakatomiLevelManager.h b/Source/Nakatomi/NakatomiLevelManager.h index 7fa4493..db14fde 100644 --- a/Source/Nakatomi/NakatomiLevelManager.h +++ b/Source/Nakatomi/NakatomiLevelManager.h @@ -19,7 +19,7 @@ private: UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true")) TSoftObjectPtr 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: