Fixed NeedReloadText & Added it so you cant spam fire shotgun

This commit is contained in:
MH261677 2024-02-23 18:59:12 +00:00
parent 2fc034892d
commit b74e7bee9a
5 changed files with 40 additions and 5 deletions

View File

@ -18,10 +18,18 @@ void AShotgunClass::BeginPlay()
Super::BeginPlay();
}
void AShotgunClass::ClickDetectionTimer()
{
Super::ClickDetectionTimer();
GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Magenta, TEXT("ClickDetectionTimer Activated"));
}
void AShotgunClass::Fire()
{
if(currentAmmoCount > 0)
if(currentAmmoCount > 0 && !bSingleShotOnly)
{
bSingleShotOnly = true;
GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Magenta, TEXT("Fire Activated"));
traceStart = GunStartArrow->GetComponentLocation();
if (GetWorldTimerManager().IsTimerActive(timerHandle)) return;
for (int i = 0; i < 5; i++)
@ -30,11 +38,12 @@ void AShotgunClass::Fire()
traceEnd = newStartTrace + (GunStartArrow->GetForwardVector() * BulletDistance);
GetWorld()->LineTraceSingleByChannel(outHit, newStartTrace, traceEnd, ECC_Visibility, collisionParams);
DrawDebugLine(this->GetWorld(), newStartTrace, traceEnd, FColor::Black , false, 0.2f, 0U, 0.2f);
currentAmmoCount --;
}
currentAmmoCount --;
playerControllerRef->PlayerCameraManager->StartCameraShake(CameraShakeClass, 1);
GenerateRecoilVector();
ClickDetectionTimer();
this->GetWorld()->GetTimerManager().SetTimer(ShotgunTimerHandle, this, &AShotgunClass::StopFire, FireRate, false);
bulletCountShoot += 1;
bStopShooting = false;
if (outHit.bBlockingHit)
@ -51,10 +60,23 @@ void AShotgunClass::Fire()
if (!Cast<AAICharacter>(outHit.GetActor())) return;
Cast<AAICharacter>(outHit.GetActor())->TakeDamage(tempWeaponDamage, FPointDamageEvent(), GetWorld()->GetFirstPlayerController(), this);
}
HideNeedReloadUI();
}
else if(currentAmmoCount <= 0)
{
UE_LOG(LogTemp, Display, TEXT("No ammo, Ammo count: %d"), currentAmmoCount);
ShowNeedReloadUI();
}
}
void AShotgunClass::CancelFire()
{
Super::CancelFire();
}
void AShotgunClass::StopFire()
{
bSingleShotOnly = false;
}

View File

@ -22,9 +22,20 @@ public:
UPROPERTY(EditAnywhere, Category = "Weapon")
FVector ShotgunBulletSpread;
FTimerHandle ShotgunTimerHandle;
void StopFire();
bool bSingleShotOnly;
protected:
virtual void Fire() override;
virtual void BeginPlay() override;
virtual void ClickDetectionTimer() override;
virtual void CancelFire() override;
};

View File

@ -72,10 +72,12 @@ void ASniperClass::Fire()
if (!Cast<AAICharacter>(outHit.GetActor())) return;
Cast<AAICharacter>(outHit.GetActor())->TakeDamage(tempWeaponDamage, FPointDamageEvent(), GetWorld()->GetFirstPlayerController(), this);
}
HideNeedReloadUI();
}
else if(currentAmmoCount <= 0)
{
UE_LOG(LogTemp, Display, TEXT("No ammo, Ammo count: %d"), currentAmmoCount);
ShowNeedReloadUI();
}
}