add timer for player
This commit is contained in:
Binary file not shown.
@@ -2,6 +2,8 @@
|
||||
|
||||
|
||||
#include "PlayerCharacter.h"
|
||||
#include "TimerManager.h"
|
||||
|
||||
|
||||
|
||||
// Sets default values
|
||||
@@ -20,6 +22,7 @@ APlayerCharacter::APlayerCharacter()
|
||||
camera->SetupAttachment(SpringArmComponent);
|
||||
isPlayAnimRepair = false;
|
||||
crushedItem = nullptr;
|
||||
isStaminaDecreace = false;
|
||||
}
|
||||
|
||||
// Called when the game starts or when spawned
|
||||
@@ -63,6 +66,11 @@ void APlayerCharacter::moveFD(float value)
|
||||
{
|
||||
const FVector Forward = FVector(1, 0, 0);
|
||||
AddMovementInput(Forward, value);
|
||||
if (isStaminaDecreace != true)
|
||||
{
|
||||
isStaminaDecreace = !isStaminaDecreace;
|
||||
GetWorldTimerManager().SetTimer(TimerForStamina, this, &APlayerCharacter::staminaDecreace, 0.5f, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,27 +80,41 @@ void APlayerCharacter::moveRL(float value)
|
||||
{
|
||||
const FVector Right = FVector(0, 1, 0);
|
||||
AddMovementInput(Right, value);
|
||||
if(isStaminaDecreace != true)
|
||||
{
|
||||
isStaminaDecreace = !isStaminaDecreace;
|
||||
GetWorldTimerManager().SetTimer(TimerForStamina, this, &APlayerCharacter::staminaDecreace, 0.5f, false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void APlayerCharacter::moveFrontOn()
|
||||
{
|
||||
staminaDecreace();
|
||||
//isStaminaDecreace = !isStaminaDecreace;
|
||||
//GetWorldTimerManager().SetTimer(TimerForStamina, this, &APlayerCharacter::staminaDecreace, 0.5f, false);
|
||||
//staminaDecreace();
|
||||
}
|
||||
|
||||
void APlayerCharacter::moveBackOn()
|
||||
{
|
||||
staminaDecreace();
|
||||
isStaminaDecreace = !isStaminaDecreace;
|
||||
GetWorldTimerManager().SetTimer(TimerForStamina, this, &APlayerCharacter::staminaDecreace, 0.5f, true);
|
||||
//staminaDecreace();
|
||||
}
|
||||
|
||||
void APlayerCharacter::moveRightOn()
|
||||
{
|
||||
staminaDecreace();
|
||||
//isStaminaDecreace = !isStaminaDecreace;
|
||||
//GetWorldTimerManager().SetTimer(TimerForStamina, this, &APlayerCharacter::staminaDecreace, 0.5f, false);
|
||||
//staminaDecreace();
|
||||
}
|
||||
|
||||
void APlayerCharacter::moveLeftOn()
|
||||
{
|
||||
staminaDecreace();
|
||||
//isStaminaDecreace = !isStaminaDecreace;
|
||||
//GetWorldTimerManager().SetTimer(TimerForStamina, this, &APlayerCharacter::staminaDecreace, 0.5f, false);
|
||||
//staminaDecreace();
|
||||
}
|
||||
|
||||
void APlayerCharacter::OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor,
|
||||
@@ -175,10 +197,12 @@ void APlayerCharacter::repairStart()
|
||||
|
||||
void APlayerCharacter::staminaDecreace()
|
||||
{
|
||||
if(gameInstance->getCurrentStamina() >= 0)
|
||||
GetWorldTimerManager().ClearTimer(TimerForStamina);
|
||||
if(gameInstance->getCurrentStamina() >= 0 && isStaminaDecreace)
|
||||
{
|
||||
gameInstance->setCurrentStamina(FMath::Clamp<float>(gameInstance->getCurrentStamina() - 0.3, 0.0f,
|
||||
gameInstance->setCurrentStamina(FMath::Clamp<float>(gameInstance->getCurrentStamina() - 0.1f, 0.0f,
|
||||
gameInstance->getMaxStamina()));
|
||||
isStaminaDecreace = !isStaminaDecreace;
|
||||
}else
|
||||
{
|
||||
// animation sleep
|
||||
|
||||
@@ -75,6 +75,10 @@ protected:
|
||||
float MaxStaminaStamina;
|
||||
UPROPERTY(EditAnywhere, Category = "Data")
|
||||
UWBIFGameInstance* gameInstance;
|
||||
UPROPERTY()
|
||||
bool isStaminaDecreace;
|
||||
UPROPERTY()
|
||||
FTimerHandle TimerForStamina;
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user