UE随机产生角色

阅读: 评论:0

UE随机产生角色

UE随机产生角色

在场景中可以随便产生一些Actor

  1. 新建C++类:SpawnVolume
  2. 打开VS2019编辑类
// 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);}
  1. 创建蓝图类
  2. 把创建的蓝图类拖动到场景中,点击【运行】即可
    aaa

本文发布于:2024-01-31 04:27:38,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170664646125470.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:角色   UE
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23