Skip to content

Commit cba48bf

Browse files
committed
Added spawn timer
1 parent e16341a commit cba48bf

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

Content/Maps/CollectionLevel.umap

-891 Bytes
Binary file not shown.

Source/BatteryCollector/SpawnVolume.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,19 @@ ASpawnVolume::ASpawnVolume()
1515
// Create the Box Component to represent the spawn volume
1616
WhereToSpawn = CreateDefaultSubobject<UBoxComponent>(TEXT("WhereToSpawn"));
1717
RootComponent = WhereToSpawn;
18+
19+
//Set the spawn delay range
20+
SpawnDelayRangeLow = 1.0f;
21+
SpawnDelayRangeHigh = 4.5f;
1822
}
1923

2024
// Called when the game starts or when spawned
2125
void ASpawnVolume::BeginPlay()
2226
{
2327
Super::BeginPlay();
2428

29+
SpawnDelay = FMath::FRandRange(SpawnDelayRangeLow, SpawnDelayRangeHigh);
30+
GetWorldTimerManager().SetTimer(SpawnTimer, this, &ASpawnVolume::SpawnPickup, SpawnDelay, false);
2531
}
2632

2733
// Called every frame
@@ -65,6 +71,9 @@ void ASpawnVolume::SpawnPickup()
6571

6672
// spawn the pickup
6773
APickup* const SpawnedPickup = World->SpawnActor<APickup>(WhatToSpawn, SpawnLocation, SpawnRotation, SpawnParams);
74+
75+
SpawnDelay = FMath::FRandRange(SpawnDelayRangeLow, SpawnDelayRangeHigh);
76+
GetWorldTimerManager().SetTimer(SpawnTimer, this, &ASpawnVolume::SpawnPickup, SpawnDelay, false);
6877
}
6978
}
7079

Source/BatteryCollector/SpawnVolume.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ class BATTERYCOLLECTOR_API ASpawnVolume : public AActor
3232
UPROPERTY(EditAnywhere, Category = "Spawning")
3333
TSubclassOf<class APickup> WhatToSpawn;
3434

35+
FTimerHandle SpawnTimer;
36+
37+
/** Minimum spawn delay */
38+
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spawning")
39+
float SpawnDelayRangeLow;
40+
41+
/** Maximum spawn delay */
42+
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spawning")
43+
float SpawnDelayRangeHigh;
44+
3545
private:
3646
/** Box Component to specify where pickups should be spawned */
3747
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Spawning", meta = (AllowPrivateAccess = "true"))
@@ -40,4 +50,6 @@ class BATTERYCOLLECTOR_API ASpawnVolume : public AActor
4050
/** Handle spawning a new pickup */
4151
void SpawnPickup();
4252

53+
/** The current spawn delay */
54+
float SpawnDelay;
4355
};

0 commit comments

Comments
 (0)