UnrealScripterAI
Discord ↗
Link Copied to Clipboard
×
"create a zombie spawner"
AZombieSpawner::AZombieSpawner() { PrimaryActorTick.bCanEverTick = true; SpawnCollision = CreateDefaultSubobject<UBoxComponent>(TEXT("Spawn Collision")); SpawnCollision->InitBoxExtent(FVector(200.0f, 200.0f, 200.0f)); SpawnCollision->SetCollisionProfileName(TEXT("Trigger")); RootComponent = SpawnCollision; SpawnCollision->OnComponentBeginOverlap.AddDynamic(this, &AZombieSpawner::OnOverlapBegin); } void AZombieSpawner::OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult) { // Spawn a zombie at the spawner's location GetWorld()->SpawnActor<AZombie>(ZombieClass, GetActorLocation(), GetActorRotation()); }