153 - Pickup Class
This commit is contained in:
parent
4227a898d4
commit
3fae6c46d7
Binary file not shown.
|
@ -0,0 +1,64 @@
|
||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "Pickup.h"
|
||||||
|
|
||||||
|
#include "Components/SphereComponent.h"
|
||||||
|
#include "Kismet/GameplayStatics.h"
|
||||||
|
#include "Sound/SoundCue.h"
|
||||||
|
|
||||||
|
APickup::APickup()
|
||||||
|
{
|
||||||
|
PrimaryActorTick.bCanEverTick = true;
|
||||||
|
bReplicates = true;
|
||||||
|
|
||||||
|
RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
|
||||||
|
|
||||||
|
OverlapSphere = CreateDefaultSubobject<USphereComponent>(TEXT("OverlapSphere"));
|
||||||
|
OverlapSphere->SetupAttachment(RootComponent);
|
||||||
|
OverlapSphere->SetSphereRadius(150.f);
|
||||||
|
OverlapSphere->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
|
||||||
|
OverlapSphere->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore);
|
||||||
|
OverlapSphere->SetCollisionResponseToChannel(ECollisionChannel::ECC_Pawn, ECollisionResponse::ECR_Overlap);
|
||||||
|
|
||||||
|
PickupMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("PickupMesh"));
|
||||||
|
PickupMesh->SetupAttachment(OverlapSphere);
|
||||||
|
PickupMesh->SetCollisionEnabled(ECollisionEnabled::NoCollision);
|
||||||
|
}
|
||||||
|
|
||||||
|
void APickup::BeginPlay()
|
||||||
|
{
|
||||||
|
Super::BeginPlay();
|
||||||
|
|
||||||
|
if (HasAuthority())
|
||||||
|
{
|
||||||
|
OverlapSphere->OnComponentBeginOverlap.AddDynamic(this, &APickup::OnSphereOverlap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void APickup::OnSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex,
|
||||||
|
bool bFromSweep, const FHitResult& SweepResult)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void APickup::Tick(float DeltaTime)
|
||||||
|
{
|
||||||
|
Super::Tick(DeltaTime);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void APickup::Destroyed()
|
||||||
|
{
|
||||||
|
Super::Destroyed();
|
||||||
|
|
||||||
|
if (PickupSound)
|
||||||
|
{
|
||||||
|
UGameplayStatics::PlaySoundAtLocation(
|
||||||
|
this,
|
||||||
|
PickupSound,
|
||||||
|
GetActorLocation()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "GameFramework/Actor.h"
|
||||||
|
#include "Pickup.generated.h"
|
||||||
|
|
||||||
|
UCLASS()
|
||||||
|
class BLASTER_API APickup : public AActor
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
APickup();
|
||||||
|
virtual void Tick(float DeltaTime) override;
|
||||||
|
virtual void Destroyed() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
virtual void OnSphereOverlap(
|
||||||
|
UPrimitiveComponent* OverlappedComponent,
|
||||||
|
AActor* OtherActor,
|
||||||
|
UPrimitiveComponent* OtherComp,
|
||||||
|
int32 OtherBodyIndex,
|
||||||
|
bool bFromSweep,
|
||||||
|
const FHitResult& SweepResult
|
||||||
|
);
|
||||||
|
|
||||||
|
private:
|
||||||
|
UPROPERTY(EditAnywhere)
|
||||||
|
class USphereComponent* OverlapSphere;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere)
|
||||||
|
class USoundCue* PickupSound;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere)
|
||||||
|
UStaticMeshComponent* PickupMesh;
|
||||||
|
|
||||||
|
public:
|
||||||
|
};
|
Loading…
Reference in New Issue