Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Fill out your copyright notice in the Description page of Project Settings.
- #include "FPS2.h"
- #include "BaseCharacter_C.h"
- // Sets default values
- ABaseCharacter_C::ABaseCharacter_C()
- {
- // Set this character 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 ABaseCharacter_C::BeginPlay()
- {
- Super::BeginPlay();
- }
- // Called every frame
- void ABaseCharacter_C::Tick(float DeltaTime)
- {
- Super::Tick(DeltaTime);
- }
- // Called to bind functionality to input
- void ABaseCharacter_C::SetupPlayerInputComponent(class UInputComponent* InputComponent)
- {
- Super::SetupPlayerInputComponent(InputComponent);
- }
- ///////////////////////////////////////////////////
- //Step 1: Implement the CalculateHealth function.
- void ABaseCharacter_C::CalculateHealth(float Delta)
- {
- Health += Delta;
- Health = FMath::Clamp(Health, 0.0f, HealthMax);
- HealthPerc = Health / HealthMax;
- CalculateDead();
- }
- //Step 2: Implement the CalculateDead function.
- void ABaseCharacter_C::CalculateDead()
- {
- if (Health <= 0)
- {
- IsDead = true;
- OnDeath_Implementation();
- }
- else
- {
- IsDead = false;
- }
- }
- void ABaseCharacter_C::Kill()
- {
- CalculateHealth(-Health);
- }
- void ABaseCharacter_C::OnDeath_Implementation(){}
- #if WITH_EDITOR
- //Step 3: Implement the remainder of our helper code, used by the editor when we change values.
- void ABaseCharacter_C::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
- {
- IsDead = false;
- Health = 100;
- Super::PostEditChangeProperty(PropertyChangedEvent);
- CalculateDead();
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement