1 // Fill out your copyright notice in the Description page of Project Settings.
2
3 #include "MyPawn.h"
4 #include "Runtime/Engine/Classes/Components/BoxComponent.h"
5 #include "Runtime/Engine/Classes/Components/SphereComponent.h"// USphereComponent 引用
6 #include "Runtime/CoreUObject/Public/UObject/ConstructorHelpers.h" // ConstructorHelpers 引用
7 #include "Runtime/Engine/Classes/Particles/ParticleSystemComponent.h"//UParticleSystemComponent 引用
8 #include "Runtime/Engine/Classes/GameFramework/SpringArmComponent.h"//UStaticMeshComponent 引用
9 // Sets default values
10 AMyPawn::AMyPawn()
11 {
12 // Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
13 PrimaryActorTick.bCanEverTick = true;
14 USphereComponent * SphereComponent = CreateDefaultSubobject<USphereComponent>("RootComponent");
15 RootComponent = SphereComponent;//这里不一定非要用物体组件
16
17 //创建静态网格物体
18 UStaticMeshComponent * SphereVisual = CreateDefaultSubobject<UStaticMeshComponent>("VisualRepresentation");
19 SphereVisual->SetupAttachment(RootComponent);
20
21 //打开素材库
22 static ConstructorHelpers::FObjectFinder<UStaticMesh> SphereVisualAssetWzh(TEXT("/Game/StarterContent/Shapes/Shape_Sphere.Shape_Sphere"));
23 if (SphereVisualAssetWzh.Succeeded()) {
24 SphereVisual->SetStaticMesh(SphereVisualAssetWzh.Object);
25 SphereVisual->SetRelativeLocation(FVector(0.0f, 0.0f, -40.0f));//设置位置0,0,0为初始位置
26 SphereVisual->SetWorldScale3D(FVector(0.8f));//SetWorldScale3D 设置组件在世界空间中的变换倍数。 倍数以原来模型大小为基准
27 }
28 // 创建一个可启用或停用的粒子系统
29 OurParticleSystem = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("MovementParticles"));
30 OurParticleSystem->SetupAttachment(SphereVisual);
31 OurParticleSystem->SetRelativeLocation(FVector(-20.0f, 0.0f, 20.0f));
32 static ConstructorHelpers::FObjectFinder<UParticleSystem> ParticleAsset(TEXT("/Game/StarterContent/Particles/P_Fire.P_Fire"));
33 if (ParticleAsset.Succeeded())
34 {
35 OurParticleSystem->SetTemplate(ParticleAsset.Object);
36 }
37
38 }
39
40 // Called when the game starts or when spawned
41 void AMyPawn::BeginPlay()
42 {
43 Super::BeginPlay();
44
45
46 }
47
48 // Called every frame
49 void AMyPawn::Tick(float DeltaTime)
50 {
51 Super::Tick(DeltaTime);
52
53 }
54
55 // Called to bind functionality to input
56 void AMyPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
57 {
58 Super::SetupPlayerInputComponent(PlayerInputComponent);
59
60 }