在场景中可以随便产生一些Actor
// Fill out your copyright notice in the Description page of Project Settings.#pragma once#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include ated.h"UCLASS()
class FIRSTPROJECT_API ASpwanVolume : public AActor {GENERATED_BODY()public:// Sets default values for this actor's propertiesASpwanVolume();UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category ="Spawning")class UBoxComponent* spawningBox = nullptr;UFUNCTION(BlueprintPure, Category = "Spawning")FVector getSpawnPoint();UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Spawning")TSubclassOf<class AAnimal> pawnToSpawn;
protected:// Called when the game starts or when spawnedvirtual void BeginPlay() override;public:// Called every framevirtual void Tick(float DeltaTime) override;};
// Fill out your copyright notice in the Description page of Project Settings.#include "SpwanVolume.h"
#include "Components/BoxComponent.h"
#include "Kismet/KismetMathLibrary.h"// Sets default values
ASpwanVolume::ASpwanVolume() {// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.PrimaryActorTick.bCanEverTick = true;spawningBox = CreateDefaultSubobject<UBoxComponent>(TEXT("SpawningBox"));RootComponent = spawningBox;
}FVector ASpwanVolume::getSpawnPoint() {FVector boxExtent = spawningBox->GetScaledBoxExtent();FVector boxOrigin = spawningBox->GetComponentLocation();FVector randPt = UKismetMathLibrary::RandomPointInBoundingBox(boxOrigin, boxExtent);return randPt;
}// Called when the game starts or when spawned
void ASpwanVolume::BeginPlay() {Super::BeginPlay();}// Called every frame
void ASpwanVolume::Tick(float DeltaTime) {Super::Tick(DeltaTime);}
本文发布于:2024-01-31 04:27:38,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170664646125470.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |