Pawn继承与aactor,能通过玩家输入和ai驱动。
AutoPossessPlayer = EAutoReceiveInput::Player0;设置吸收输入的pawn,添加多个此类pawn,Player0取得是最新添加到场景中的pawn.
UPROPERTY属性可以让代码中变量在ed中可见,同时不会每次跑场景都重新设置变量,赋予EditAnywhere属性可以在编辑器中赋值。
一个控制pawn移动和形变的例子。
UCLASS()
class BASICPROJ_API AMyPawn : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn's properties
AMyPawn();
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called every frame
virtual void Tick( float DeltaSeconds ) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;
private:
void MoveX(float delta);
void MoveY(float delta);
void StartGrow();
void StopGrow();
FVector CurrentVelocity;
bool bGrowing;