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





  • 相关阅读:
    实现一个WEBIM
    拼写纠错
    UML系列图用例图
    [bzoj1670][Usaco2006 Oct]Building the Moat
    [bzoj3626][LNOI2014]LCA
    转:用JS写的一个树型结构
    一个购物车中修改商品数量的实列
    网站访问统计在Global.asax中的配置的深入讨论
    转:JavaScript中的三级联动
    转:用Sql Server存储上载图片字体
  • 原文地址:https://www.cnblogs.com/yangshengjing/p/12049002.html
Copyright © 2011-2022 走看看