用C++创建一个发射平台,可以把重叠的角色弹射出去,也可以把开启了物理模拟的物体弹射出去。
这是Udemy上教程的挑战任务,最近一直在跟着教程做,从一开始的完全懵逼到现在逐渐理解,非常有收获。
代码如下:
FPSLaunchPad.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "FPSLaunchPad.generated.h"
class UStaticMeshComponent;
class UBoxComponent;
class UArrowComponent;
UCLASS()
class FPSGAME_API AFPSLaunchPad : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AFPSLaunchPad();
protected:
//创建必须的组件,一个用于计算重叠的盒子和一个mesh
UPROPERTY(VisibleAnywhere, Category = "Components")
UStaticMeshComponent* MeshComp;
UPROPERTY(VisibleAnywhere, Category = "Components")
UBoxComponent* OverlapBox;
//绑定重叠函数
UFUNCTION()
void OverlapLaunchPad(UPrimitiveComponent* OverlappedComponent, AActor* Other