1.如何获取绑定到的Actor对象
GetOwner:从Component继承来的
也就是说归属关系已经被Actor和Component封装好了
2.如何出发开关门事件
1.如何获取绑定到的Actor对象
GetOwner:从Component继承来的
也就是说归属关系已经被Actor和Component封装好了
2.如何出发开关门事件
// Fill out your copyright notice in the Description page of Project Settings. #include "OpenDoor.h" #include "GameFramework/Actor.h" // Sets default values for this component's properties UOpenDoor::UOpenDoor() { // Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features // off to improve performance if you don't need them. PrimaryComponentTick.bCanEverTick = true; // ... } // Called when the game starts void UOpenDoor::BeginPlay() { Super::BeginPlay(); // ... //得到所在Actor 设置这个Actor的属性 AActor* Actor = GetOwner(); // pick =y yaw = z roll= x FRotator NewRotator = FRotator(90, 0, 0); Actor->SetActorRotation(NewRotator); } // Called every frame void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); // ... }
使用AActor* 需要引用的库:#include "GameFramework/Actor.h"
OpenDoor.cpp
void UOpenDoor::BeginPlay()
{
Super::BeginPlay();
// 得到所在的Actor 设置这个Actor的属性
AActor* Actor = GetOwner();
// pitch=y yaw=z roll=x
FRotator NewRotator = FRotator(0,90.0);
Actor->SetActorRotation(NewRotator);
}
世界大纲视图 里面的类型继承自Actor
世界大纲视图,文件多,可以创建文件夹统一管理
点击世界大纲视图里面的小眼睛,可以隐藏选中的,可以用来确保没有遗漏物体
命名习惯
AActor
UOpenDoor
bCanEverTick
Actor 是个指针,同时这还是个对象,要调用它的方法,需要使用 ->
并不是指针拥有的函数,而是对象的函数
在Visual Studio 保存了代码,需要在UE4编辑器的工具栏点击 【编译】
可以移动的物体才能旋转,需要在细节面板,变换--移动性,设置为可移动
显示有用的调试信息:
窗口---开发者工具---输入日志
Windows---Developer Tools---Output Log
每次修改完代码,记得点【编译】!!!