diff --git a/Content/Blueprints/Pickups/BP_Pickup.uasset b/Content/Blueprints/Pickups/BP_Pickup.uasset new file mode 100644 index 0000000..dbee46e Binary files /dev/null and b/Content/Blueprints/Pickups/BP_Pickup.uasset differ diff --git a/Source/Blaster/Pickups/Pickup.cpp b/Source/Blaster/Pickups/Pickup.cpp new file mode 100644 index 0000000..7e6ce1f --- /dev/null +++ b/Source/Blaster/Pickups/Pickup.cpp @@ -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(TEXT("Root")); + + OverlapSphere = CreateDefaultSubobject(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(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() + ); + } +} + diff --git a/Source/Blaster/Pickups/Pickup.h b/Source/Blaster/Pickups/Pickup.h new file mode 100644 index 0000000..ffda03c --- /dev/null +++ b/Source/Blaster/Pickups/Pickup.h @@ -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: +};