76 - Projectile Hit Events
This commit is contained in:
parent
99de487299
commit
ffa9bfc84c
Binary file not shown.
|
@ -6,6 +6,7 @@
|
||||||
#include "Components/BoxComponent.h"
|
#include "Components/BoxComponent.h"
|
||||||
#include "GameFramework/ProjectileMovementComponent.h"
|
#include "GameFramework/ProjectileMovementComponent.h"
|
||||||
#include "Kismet/GameplayStatics.h"
|
#include "Kismet/GameplayStatics.h"
|
||||||
|
#include "Sound/SoundCue.h"
|
||||||
|
|
||||||
AProjectile::AProjectile()
|
AProjectile::AProjectile()
|
||||||
{
|
{
|
||||||
|
@ -39,6 +40,31 @@ void AProjectile::BeginPlay()
|
||||||
EAttachLocation::KeepWorldPosition
|
EAttachLocation::KeepWorldPosition
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (HasAuthority())
|
||||||
|
{
|
||||||
|
CollisionBox->OnComponentHit.AddDynamic(this, &AProjectile::OnHit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AProjectile::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
|
||||||
|
{
|
||||||
|
Destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AProjectile::Destroyed()
|
||||||
|
{
|
||||||
|
Super::Destroyed();
|
||||||
|
|
||||||
|
if (ImpactParticles)
|
||||||
|
{
|
||||||
|
UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), ImpactParticles, GetActorTransform());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImpactSound)
|
||||||
|
{
|
||||||
|
UGameplayStatics::PlaySoundAtLocation(this, ImpactSound, GetActorLocation());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AProjectile::Tick(float DeltaTime)
|
void AProjectile::Tick(float DeltaTime)
|
||||||
|
|
|
@ -19,7 +19,11 @@ public:
|
||||||
protected:
|
protected:
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
public:
|
UFUNCTION()
|
||||||
|
virtual void OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit);
|
||||||
|
virtual void Destroyed() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere)
|
UPROPERTY(EditAnywhere)
|
||||||
class UBoxComponent* CollisionBox;
|
class UBoxComponent* CollisionBox;
|
||||||
|
@ -31,4 +35,10 @@ public:
|
||||||
class UParticleSystem* Tracer;
|
class UParticleSystem* Tracer;
|
||||||
|
|
||||||
class UParticleSystemComponent* TracerComponent;
|
class UParticleSystemComponent* TracerComponent;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere)
|
||||||
|
UParticleSystem* ImpactParticles;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere)
|
||||||
|
class USoundCue* ImpactSound;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue