Added Appropriate Weapon Switching for Both Primary and Secondary
This commit is contained in:
parent
9da3eed21b
commit
065984e21b
@ -278,7 +278,6 @@ void AEndlessVendettaCharacter::EquipPrimary()
|
||||
spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
||||
FAttachmentTransformRules AttachmentRules(EAttachmentRule::SnapToTarget, true);
|
||||
FDetachmentTransformRules DetatchRules(EDetachmentRule::KeepWorld, false);
|
||||
|
||||
if (bIsReloading) return;
|
||||
if (IsValid(PrimaryWeapon))
|
||||
{
|
||||
@ -292,32 +291,29 @@ void AEndlessVendettaCharacter::EquipPrimary()
|
||||
GLog->Log("Primary Weapon Put Away");
|
||||
return;
|
||||
}
|
||||
if(bIsWeaponPickedUp)
|
||||
{
|
||||
PrimaryWeaponActor = GetWorld()->SpawnActor<AActor>(PrimaryWeaponClass, spawnParams);
|
||||
bIsWeaponPickedUp = false;
|
||||
}
|
||||
|
||||
if (IsValid(SecondaryWeapon)) EquipSecondary();
|
||||
|
||||
if (GadgetManager->IsValidReconGadget() && GadgetManager->IsReconEquipped() && !GadgetManager->TryToUnequipRecon()) return;
|
||||
if (GadgetManager->IsValidCombatGadget() && GadgetManager->IsCombatEquipped() && !GadgetManager->TryToUnequipCombat()) return;
|
||||
|
||||
|
||||
//Creating a new actor object called PrimaryWeapon that is based off primaryweaponClass
|
||||
|
||||
//Changing PrimaryWeaponActor to ABaseWeaponClass type instead of actor and storing it into PrimaryWeapon which is a ABaseClass Object
|
||||
//We do this because we need to check if PrimaryWeapon is equipped and we want primaryweapon to be ABaseWeapon type and not a generic AActor
|
||||
|
||||
if(!IsValid(PrimaryWeapon))
|
||||
{
|
||||
bHasRifle = true;
|
||||
if(!bIsPrimaryWeaponCreated)
|
||||
{
|
||||
//Creating a new actor object called PrimaryWeapon that is based off primaryweaponClass
|
||||
//Changing PrimaryWeaponActor to ABaseWeaponClass type instead of actor and storing it into PrimaryWeapon which is a ABaseClass Object
|
||||
//We do this because we need to check if PrimaryWeapon is equipped and we want primaryweapon to be ABaseWeapon type and not a generic AActor
|
||||
PrimaryWeaponActor = GetWorld()->SpawnActor<AActor>(PrimaryWeaponClass, spawnParams);
|
||||
PrimaryWeaponActor->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint"));
|
||||
PrimaryWeapon = Cast<ABaseWeaponClass>(PrimaryWeaponActor);
|
||||
PrimaryWeapon->SetActorHiddenInGame(false);
|
||||
bIsPrimaryWeaponCreated = true;
|
||||
}
|
||||
//UE_LOG(LogTemp, Warning, TEXT("Primary Weapon Is Hidden: %hhd"), PrimaryWeapon->IsHidden());
|
||||
GLog->Log("Primary Weapon Equipped");
|
||||
}
|
||||
PrimaryWeaponActor->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint"));
|
||||
PrimaryWeapon = Cast<ABaseWeaponClass>(PrimaryWeaponActor);
|
||||
PrimaryWeapon->SetActorHiddenInGame(false);
|
||||
@ -345,6 +341,12 @@ void AEndlessVendettaCharacter::EquipSecondary()
|
||||
return;
|
||||
}
|
||||
|
||||
if(bIsWeaponPickedUp)
|
||||
{
|
||||
PrimaryWeaponActor = GetWorld()->SpawnActor<AActor>(PrimaryWeaponClass, spawnParams);
|
||||
bIsWeaponPickedUp = false;
|
||||
}
|
||||
|
||||
if (IsValid(PrimaryWeapon)) EquipPrimary();
|
||||
|
||||
if (GadgetManager->IsValidReconGadget() && GadgetManager->IsReconEquipped() && !GadgetManager->TryToUnequipRecon()) return;
|
||||
@ -372,13 +374,28 @@ void AEndlessVendettaCharacter::EquipSecondary()
|
||||
|
||||
void AEndlessVendettaCharacter::WeaponSwitcher(AActor* Outhit)
|
||||
{
|
||||
if(Outhit->ActorHasTag("PrimaryWeapon"))
|
||||
{
|
||||
if (IsValid(PrimaryWeapon))
|
||||
{
|
||||
EquipPrimary();
|
||||
}
|
||||
bIsWeaponPickedUp = true;
|
||||
PrimaryWeaponClass = Outhit->GetClass();
|
||||
Outhit->Destroy();
|
||||
EquipPrimary();
|
||||
}
|
||||
if(Outhit->ActorHasTag("SecondaryWeapon"))
|
||||
{
|
||||
if (IsValid(SecondaryWeapon))
|
||||
{
|
||||
EquipSecondary();
|
||||
}
|
||||
bIsWeaponPickedUp = true;
|
||||
SecondaryWeaponClass = Outhit->GetClass();
|
||||
Outhit->Destroy();
|
||||
EquipSecondary();
|
||||
}
|
||||
}
|
||||
|
||||
//Calls the fire function in the baseWeaponClass
|
||||
|
@ -85,6 +85,7 @@ public:
|
||||
AActor* SecondaryWeaponActor;
|
||||
bool bIsPrimaryWeaponCreated = false;
|
||||
bool bIsSecondaryWeaponCreated = false;
|
||||
bool bIsWeaponPickedUp = false;
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
Loading…
x
Reference in New Issue
Block a user