• 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

  • 相关阅读:
    unity urp 实现遮挡显示角色轮廓
    【首测】两款OpenCV 人工智能深度相机OAK PoE
    shiro-第一篇-基本介绍及使用
    PCB线路板蛇形布线要注意哪些问题?
    一篇五分生信临床模型预测文章代码复现——Figure 10.机制及肿瘤免疫浸润(四)
    web 前台页面内弹出框(一)
    python常用内置函数的介绍和使用
    springboot就业信息管理系统springboot32
    一文了解Python中的while循环语句
    SkyWalking9.5.0安装与SpringBoot性能链路监控
  • 原文地址:https://blog.csdn.net/wb175208/article/details/128052085