// Fill out your copyright notice in the Description page of Project Settings. #include "WaveSubsystem.h" void UWaveSubsystem::Init(const TArray InWaves, const int32 CurrWave = 0) { CurrentWave = CurrWave; Waves = InWaves; } int32 UWaveSubsystem::SpawnWave(const float InVerticalSpacing, const float InHorizontalOffset, const int InNumRows) { NumRows = InNumRows; HorizontalOffset = InHorizontalOffset; VerticalSpacing = InVerticalSpacing; SpawnQueue = Waves[CurrentWave]->GetUnits(); const auto NumUnits = SpawnQueue.Num(); SpawnUnits(); GetWorld()->GetTimerManager().SetTimer( SpawnTimerHandle, this, &UWaveSubsystem::SpawnUnits, 0.5f, true); CurrentWave++; return NumUnits; } void UWaveSubsystem::SpawnUnits() { for(auto i = 0; i < NumRows; i++) { if(i + LastSpawnIndex >= SpawnQueue.Num()) { GetWorld()->GetTimerManager().ClearTimer(SpawnTimerHandle); return; } FVector Location = FVector(VerticalSpacing * i - VerticalSpacing, HorizontalOffset, 0); AActor* NewEnemy = GetWorld()->SpawnActor(SpawnQueue[i + LastSpawnIndex]->GetCharacterClass(), &Location); if(NewEnemy != nullptr) { NewEnemy->Tags.Add(TEXT("enemy")); } } LastSpawnIndex += NumRows; }