• UE4 通过按键控制Pawn比例大小


    // Fill out your copyright notice in the Description page of Project Settings.
    
    #pragma once
    
    #include "CoreMinimal.h"
    #include "GameFramework/Pawn.h"
    #include "GrowPawn.generated.h"
    
    UCLASS()
    class TRUEFPSPROJECT_API AGrowPawn : public APawn {
    	GENERATED_BODY()
    
    public:
    	// Sets default values for this pawn's properties
    	AGrowPawn();
    
    protected:
    	// Called when the game starts or when spawned
    	virtual void BeginPlay() override;
    
    public:
    	// Called every frame
    	virtual void Tick(float DeltaTime) override;
    
    	// Called to bind functionality to input
    	virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
    
    private:
    	void growScale();
    
    private:
    	bool isGrow = false;
    };
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    // Fill out your copyright notice in the Description page of Project Settings.
    
    
    #include "GrowPawn.h"
    #include "Math/UnrealMathUtility.h"
    
    // Sets default values
    AGrowPawn::AGrowPawn() {
    	// Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
    	PrimaryActorTick.bCanEverTick = true;
    
    }
    
    // Called when the game starts or when spawned
    void AGrowPawn::BeginPlay() {
    	Super::BeginPlay();
    
    }
    
    // Called every frame
    void AGrowPawn::Tick(float DeltaTime) {
    	Super::Tick(DeltaTime);
    	float scale = RootComponent->GetComponentScale().X;
    	if (isGrow) {//变大
    		scale += DeltaTime;
    	} else {
    		scale -= DeltaTime;
    	}
    
    	scale = FMath::Clamp(scale, 1.0f, 2.0f);
    	RootComponent->SetWorldScale3D(FVector(scale));
    }
    
    // Called to bind functionality to input
    void AGrowPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) {
    	Super::SetupPlayerInputComponent(PlayerInputComponent);
    
    	PlayerInputComponent->BindAction("GrowScale", IE_Pressed, this, &AGrowPawn::growScale);
    }
    
    void AGrowPawn::growScale() {
    	isGrow = !isGrow;
    }
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45

    aaa

  • 相关阅读:
    Android 13.0 user模式下解除系统进入recovery功能的限制
    ES6箭头函数
    Linux安装与配置SSH服务
    高级指针和引用,对于参数传递和赋值目标指针的意义
    显存优化综述
    vuejs - - - - - 递归组件的实现
    JAVA文件和多个参数前后台交互
    数据结构与算法 -- 数组
    uniapp生成的h5与flutter的原生进行交互
    [ROS2系列] ORBBEC(奥比中光)AstraPro相机在ROS2进行rtabmap 3D建图
  • 原文地址:https://blog.csdn.net/wb175208/article/details/128052085