11715人加入学习
(26人评价)
【旧版】Unreal基本知识案例 - 密室逃脱

旧版课程,制作完成于2017-01-11

价格 免费

GetOwner 组件所在的Actor

[展开全文]

Pitch , Yaw , Roll 的概念:
在航空中,pitch yaw ,roll
pitch 是围绕X轴旋转,也叫 俯仰角
yaw   是围绕Y轴旋转,也叫 偏航角
roll  是围绕Z轴旋转,也叫 翻滚角

pitch = y

yaw = z

roll = x

 

OpenDoor.h

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "OpenDoor.generated.h"


UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class UNREALENGINEPROJECT_API UOpenDoor : public UActorComponent
{
	GENERATED_BODY()
public:
	UOpenDoor();
protected:
	virtual void BeginPlay() override;
public:
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
	void OpenDoor();
	void CloseDoor();
private:
	AActor* Owner;
};

OpenDoor.cpp

#include "OpenDoor.h"
#include "GameFramework/Actor.h"


UOpenDoor1::UOpenDoor()
{
	PrimaryComponentTick.bCanEverTick = true;
	Owner = GetOwner();
}

void UOpenDoor::BeginPlay()
{
	Super::BeginPlay();
	OpenDoor();
}

void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
}

void UOpenDoor::OpenDoor()
{
	// 得到所在的Actor  设置这个Actor的属性
	// pitch=y  yaw=z  roll=x
	FRotator NewRotator = FRotator(0, 90, 0);
	Owner->SetActorRotation(NewRotator);
}

void UOpenDoor::CloseDoor()
{
	FRotator NewRotator = FRotator(0, 0, 0);
	Owner->SetActorRotation(NewRotator);
}

快速在CPP文件中实现函数

[展开全文]

17节3分55秒左右,每一个指针类型的变量最好判断一下是不是为空,不然后果很严重!

判断是否为空很简单

if (Owner == nullptr)
{
	UE_LOG(LogTemp, Error, TEXT("Owner为空"));
	return;
}

 

[展开全文]

授课教师

SiKi学院老师

课程特色

图文(2)
视频(37)