add new instance game and decreace stamina player
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "PlayerCharacter.h"
|
||||
|
||||
|
||||
// Sets default values
|
||||
APlayerCharacter::APlayerCharacter()
|
||||
{
|
||||
@@ -111,12 +112,12 @@ void APlayerCharacter::OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActo
|
||||
void APlayerCharacter::OnOverlapEnd(UPrimitiveComponent* OverlappedComp, AActor* OtherActor,
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
|
||||
{
|
||||
/*if ((nullptr != OtherActor) && (this != OtherActor) && (nullptr != OtherComp))
|
||||
if ((nullptr != OtherActor))
|
||||
{
|
||||
crushedItem = nullptr;
|
||||
// Turn on the light
|
||||
UE_LOG(LogTemp, Warning, TEXT("clear"));
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
void APlayerCharacter::OnRepair()
|
||||
@@ -150,16 +151,8 @@ void APlayerCharacter::UseItem()
|
||||
|
||||
void APlayerCharacter::getData()
|
||||
{
|
||||
/*instanceGame = Cast<UGameInstanceWBIF>(GetGameInstance());
|
||||
|
||||
if (IsValid(instanceGame))
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("valid"));
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("INvalid"));
|
||||
}*/
|
||||
gameInstance = Cast<UWBIFGameInstance>(GetGameInstance());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -182,10 +175,19 @@ void APlayerCharacter::repairStart()
|
||||
|
||||
void APlayerCharacter::staminaDecreace()
|
||||
{
|
||||
//instanceGame->currentStamina = FMath::Clamp<float>(instanceGame->currentStamina - 0.3, 0.0f,
|
||||
//instanceGame->maxStamina);
|
||||
if(gameInstance->getCurrentStamina() >= 0)
|
||||
{
|
||||
gameInstance->setCurrentStamina(FMath::Clamp<float>(gameInstance->getCurrentStamina() - 0.3, 0.0f,
|
||||
gameInstance->getMaxStamina()));
|
||||
}else
|
||||
{
|
||||
// animation sleep
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void APlayerCharacter::staminaHiling()
|
||||
{
|
||||
//instanceGame->currentStamina = FMath::Clamp<float>(instanceGame->currentStamina + 1, 0.0f,
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "WBIFGameInstance.h"
|
||||
|
||||
void UWBIFGameInstance::setCurrentStamina(float curStamina)
|
||||
{
|
||||
CurrentStamina = curStamina;
|
||||
}
|
||||
|
||||
void UWBIFGameInstance::setMaxStaminaStamina(float maximumStamina)
|
||||
{
|
||||
MaxStamina = maximumStamina;
|
||||
}
|
||||
|
||||
float UWBIFGameInstance::getCurrentStamina()
|
||||
{
|
||||
return CurrentStamina;
|
||||
}
|
||||
|
||||
float UWBIFGameInstance::getMaxStamina()
|
||||
{
|
||||
return MaxStamina;
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "GameFramework/SpringArmComponent.h"
|
||||
#include "Camera/CameraComponent.h"
|
||||
#include "BaseItem.h"
|
||||
#include "WBIFGameInstance.h"
|
||||
#include "PlayerCharacter.generated.h"
|
||||
|
||||
UCLASS()
|
||||
@@ -23,8 +24,8 @@ public:
|
||||
protected:
|
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override;
|
||||
// ===================Functions===================================
|
||||
// Moving
|
||||
// ===================Functions===================================
|
||||
// Moving
|
||||
UFUNCTION()
|
||||
void moveFD(float value);
|
||||
UFUNCTION()
|
||||
@@ -56,39 +57,41 @@ protected:
|
||||
UFUNCTION(Category = "Data")
|
||||
void getData();
|
||||
|
||||
|
||||
|
||||
// ===================Variables===================================
|
||||
|
||||
// ===================Variables===================================
|
||||
|
||||
UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "Camera")
|
||||
USpringArmComponent* SpringArmComponent;
|
||||
|
||||
UPROPERTY(EditAnyWhere, Category = "Camera")
|
||||
UCameraComponent* camera;
|
||||
UPROPERTY(EditAnyWhere, Category = "Data")
|
||||
ABaseItem* crushedItem;
|
||||
UPROPERTY(EditAnyWhere, Category = "Data")
|
||||
UCapsuleComponent* capsule;
|
||||
UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "Data")
|
||||
float CurrentStamina;
|
||||
UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "Data")
|
||||
float MaxStaminaStamina;
|
||||
UPROPERTY(EditAnywhere, Category = "Data")
|
||||
UWBIFGameInstance* gameInstance;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
public:
|
||||
// Called every frame
|
||||
//virtual void Tick(float DeltaTime) override;
|
||||
|
||||
// Called to bind functionality to input
|
||||
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
||||
|
||||
// ===================Variables===================================
|
||||
UPROPERTY( EditAnyWhere, BlueprintReadWrite, Category = "Data")
|
||||
// ===================Variables===================================
|
||||
UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "Data")
|
||||
bool isPlayAnimRepair;
|
||||
UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "Data")
|
||||
float CurrentStamina;
|
||||
UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "Data")
|
||||
float MaxStaminaStamina;
|
||||
|
||||
|
||||
|
||||
// ===================Functions===================================
|
||||
UFUNCTION(BlueprintCallable, BlueprintImplementableEvent, Category = "Animations")
|
||||
// ===================Functions===================================
|
||||
UFUNCTION(BlueprintImplementableEvent, BlueprintCallable, Category = "Animations")
|
||||
void startAnimRepair();
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Repair")
|
||||
@@ -98,4 +101,5 @@ public:
|
||||
void staminaDecreace();
|
||||
UFUNCTION(BlueprintCallable, Category = "Stamina")
|
||||
void staminaHiling();
|
||||
|
||||
};
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Engine/GameInstance.h"
|
||||
#include "WBIFGameInstance.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class WBIF_API UWBIFGameInstance : public UGameInstance
|
||||
{
|
||||
GENERATED_BODY()
|
||||
public:
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
/*
|
||||
* stamina player
|
||||
*/
|
||||
float CurrentStamina;
|
||||
float MaxStamina;
|
||||
public:
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "stamina player")
|
||||
void setCurrentStamina(float curStamina);
|
||||
UFUNCTION(BlueprintCallable, Category = "stamina player")
|
||||
void setMaxStaminaStamina(float maximumStamina);
|
||||
UFUNCTION(BlueprintPure, Category = "stamina player")
|
||||
float getCurrentStamina();
|
||||
UFUNCTION(BlueprintPure, Category = "stamina player")
|
||||
float getMaxStamina();
|
||||
};
|
||||
Reference in New Issue
Block a user