Add public methods to set Weapon in WeaponPickup
This commit is contained in:
parent
0e95cf7239
commit
2585404169
|
@ -25,19 +25,10 @@ void AWeaponPickup::BeginPlay()
|
||||||
|
|
||||||
if (Weapon)
|
if (Weapon)
|
||||||
{
|
{
|
||||||
FActorSpawnParameters SpawnParameters;
|
SpawnWeapon();
|
||||||
SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
|
||||||
WeaponComponent = GetWorld()->SpawnActor<AWeapon>(Weapon, SpawnParameters);
|
|
||||||
FAttachmentTransformRules TransformRules = FAttachmentTransformRules(EAttachmentRule::SnapToTarget, EAttachmentRule::SnapToTarget, EAttachmentRule::SnapToTarget, true);
|
|
||||||
WeaponComponent->AttachToComponent(RootComponent, TransformRules);
|
|
||||||
WeaponComponent->SetActorRelativeLocation(FVector(0.0f, 0.0f, 5.0f));
|
|
||||||
WeaponComponent->SetActorEnableCollision(false);
|
|
||||||
|
|
||||||
WeaponStartingLocation = WeaponComponent->GetActorLocation();
|
|
||||||
WeaponStartingLocation += ((MovementDirection * MovementDistance) / 2);
|
|
||||||
|
|
||||||
SphereComponent->OnComponentBeginOverlap.AddDynamic(this, &AWeaponPickup::OnOverlapBegin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SphereComponent->OnComponentBeginOverlap.AddDynamic(this, &AWeaponPickup::OnOverlapBegin);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called every frame
|
// Called every frame
|
||||||
|
@ -72,3 +63,29 @@ void AWeaponPickup::OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AAc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AWeaponPickup::SetWeapon(TSubclassOf<class AWeapon> weapon)
|
||||||
|
{
|
||||||
|
Weapon = weapon;
|
||||||
|
|
||||||
|
if (WeaponComponent)
|
||||||
|
{
|
||||||
|
WeaponComponent->Destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
SpawnWeapon();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AWeaponPickup::SpawnWeapon()
|
||||||
|
{
|
||||||
|
FActorSpawnParameters SpawnParameters;
|
||||||
|
SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
||||||
|
WeaponComponent = GetWorld()->SpawnActor<AWeapon>(Weapon, SpawnParameters);
|
||||||
|
FAttachmentTransformRules TransformRules = FAttachmentTransformRules(EAttachmentRule::SnapToTarget, EAttachmentRule::SnapToTarget, EAttachmentRule::SnapToTarget, true);
|
||||||
|
WeaponComponent->AttachToComponent(RootComponent, TransformRules);
|
||||||
|
WeaponComponent->SetActorRelativeLocation(FVector(0.0f, 0.0f, 5.0f));
|
||||||
|
WeaponComponent->SetActorEnableCollision(false);
|
||||||
|
|
||||||
|
WeaponStartingLocation = WeaponComponent->GetActorLocation();
|
||||||
|
WeaponStartingLocation += ((MovementDirection * MovementDistance) / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,4 +60,9 @@ public:
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
|
void OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
|
||||||
|
|
||||||
|
void SetWeapon(TSubclassOf<class AWeapon> weapon);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void SpawnWeapon();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue