zoukankan      html  css  js  c++  java
  • UE4 与 C++

     1 #pragma once
     2 
     3 #include "CoreMinimal.h"
     4 #include "GameFramework/Character.h"
     5 #include "BaseCharacter.generated.h"
     6 
     7 UCLASS(Blueprintable)
     8 class TWINSTICKSHOOTER_API ABaseCharacter : public ACharacter
     9 {
    10     GENERATED_BODY()
    11 public:
    12     //添加生命
    13     UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Base Character")
    14         float Health = 100;
    15     //是否死亡
    16     UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Category = "Base Character")
    17         bool isDead = false;
    18     //死亡计算函数
    19     virtual void CalculateDead();
    20     //生命计算函数
    21     UFUNCTION(BlueprintCallable, Category = "Base Character")
    22         virtual void CalculateHealth(float delta);
    23 #if WITH_EDITOR
    24     //修改属性
    25     virtual void PostEditChangeProperty(FPropertyChangedEvent &PropertyChangedEvent) override;
    26 #endif
    27 public:
    28     // Sets default values for this character's properties
    29     ABaseCharacter();
    30 
    31 protected:
    32     // Called when the game starts or when spawned
    33     virtual void BeginPlay() override;
    34 
    35 public:    
    36     // Called every frame
    37     virtual void Tick(float DeltaTime) override;
    38 
    39     // Called to bind functionality to input
    40     virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
    41 
    42 };

    -----------------------------------------------------------------------------------------------------------------
     1 // Fill out your copyright notice in the Description page of Project Settings.
     2 
     3 
     4 #include "BaseCharacter.h"
     5 
     6 // Sets default values
     7 ABaseCharacter::ABaseCharacter()
     8 {
     9      // Set this character to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
    10     PrimaryActorTick.bCanEverTick = true;
    11 
    12 }
    13 
    14 // Called when the game starts or when spawned
    15 void ABaseCharacter::BeginPlay()
    16 {
    17     Super::BeginPlay();
    18     
    19 }
    20 
    21 // Called every frame
    22 void ABaseCharacter::Tick(float DeltaTime)
    23 {
    24     Super::Tick(DeltaTime);
    25 
    26 }
    27 
    28 // Called to bind functionality to input
    29 void ABaseCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
    30 {
    31     Super::SetupPlayerInputComponent(PlayerInputComponent);
    32 
    33 }
    34 
    35 void ABaseCharacter::CalculateHealth(float delta)
    36 {
    37     Health += delta;
    38     CalculateDead();
    39 }
    40 void ABaseCharacter::CalculateDead()
    41 {
    42     if (Health <= 0)
    43         isDead = true;
    44     else
    45         isDead = false;
    46 
    47  }
    48 
    49 
    50 #if WITH_EDITOR
    51 void ABaseCharacter::PostEditChangeProperty(FPropertyChangedEvent &PropertyChangedEvent)
    52 {
    53     isDead = false;
    54     Health = 100;
    55     Super::PostEditChangeProperty(PropertyChangedEvent);
    56     CalculateDead();
    57 }
    58 #endif // WITH_EDITOR





  • 相关阅读:
    logging模块
    获得本机时间
    为了节约一台打印机,我也是无奈呀~~~~
    django通过管理页上传图片
    python打印爱心
    djago后台管理页面
    今天休年休找不到填年休的表了,结果就写了一个查找文件的缩引存起来方便下次用
    中间件调用顺序_______网站仿问过程
    django中间件
    py3.8安装
  • 原文地址:https://www.cnblogs.com/yangshengjing/p/12049002.html
Copyright © 2011-2022 走看看