unrealgame4/Source/ThirdPerson/Private/ActorSpawner.cpp

41 lines
998 B
C++

// All content (c) Shaun Reed 2021, all rights reserved
#include "ActorSpawner.h"
// Include the header file from the actor we want to spawn
#include "BallActor.h"
// Engine includes
#include "Components/BoxComponent.h"
// Sets default values
AActorSpawner::AActorSpawner()
{
RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("DefaultSceneRoot"));
SpawnVolume = CreateDefaultSubobject<UBoxComponent>(TEXT("SpawnVolume"));
SpawnVolume->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);
}
void AActorSpawner::SpawnActor()
{
// Get initial position and rotation, then spawn the actor
FVector SpawnLocation = GetActorLocation();
FRotator SpawnRotation = GetActorRotation();
GetWorld()->SpawnActor<ABallActor>(SpawnLocation, SpawnRotation);
}
// Called when the game starts or when spawned
void AActorSpawner::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AActorSpawner::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}