diff --git a/Content/Blueprints/Character/BP_BlasterCharacter.uasset b/Content/Blueprints/Character/BP_BlasterCharacter.uasset index 3d2206f..c16e1f9 100644 Binary files a/Content/Blueprints/Character/BP_BlasterCharacter.uasset and b/Content/Blueprints/Character/BP_BlasterCharacter.uasset differ diff --git a/Content/Blueprints/HUD/WBP_PickupWidget.uasset b/Content/Blueprints/HUD/WBP_PickupWidget.uasset new file mode 100644 index 0000000..bf03822 Binary files /dev/null and b/Content/Blueprints/HUD/WBP_PickupWidget.uasset differ diff --git a/Content/Blueprints/Weapon/BP_Weapon.uasset b/Content/Blueprints/Weapon/BP_Weapon.uasset index b060b53..c403c3b 100644 Binary files a/Content/Blueprints/Weapon/BP_Weapon.uasset and b/Content/Blueprints/Weapon/BP_Weapon.uasset differ diff --git a/Content/Maps/BlasterMap.umap b/Content/Maps/BlasterMap.umap index 1e37ac2..58eeaf0 100644 Binary files a/Content/Maps/BlasterMap.umap and b/Content/Maps/BlasterMap.umap differ diff --git a/Source/Blaster/Weapon/Weapon.cpp b/Source/Blaster/Weapon/Weapon.cpp index 35895fe..4bd0f6d 100644 --- a/Source/Blaster/Weapon/Weapon.cpp +++ b/Source/Blaster/Weapon/Weapon.cpp @@ -3,18 +3,20 @@ #include "Weapon.h" +#include "Blaster/Character/BlasterCharacter.h" #include "Components/SphereComponent.h" +#include "Components/WidgetComponent.h" AWeapon::AWeapon() { PrimaryActorTick.bCanEverTick = false; bReplicates = true; - - WeaponMesh = CreateDefaultSubobject(TEXT("WeaponMesh")); - WeaponMesh->SetupAttachment(RootComponent); - SetRootComponent(WeaponMesh) ; - + WeaponMesh = CreateDefaultSubobject(TEXT("WeaponMesh")); + WeaponMesh->SetupAttachment(WeaponMesh); // WeaponMesh instead? + + SetRootComponent(WeaponMesh); + WeaponMesh->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Block); WeaponMesh->SetCollisionResponseToChannel(ECollisionChannel::ECC_Pawn, ECollisionResponse::ECR_Ignore); WeaponMesh->SetCollisionEnabled(ECollisionEnabled::NoCollision); @@ -23,6 +25,9 @@ AWeapon::AWeapon() AreaSphere->SetupAttachment(RootComponent); AreaSphere->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore); AreaSphere->SetCollisionEnabled(ECollisionEnabled::NoCollision); + + PickupWidget = CreateDefaultSubobject(TEXT("PickupWidget")); + PickupWidget->SetupAttachment(RootComponent); } void AWeapon::BeginPlay() @@ -33,7 +38,25 @@ void AWeapon::BeginPlay() { AreaSphere->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics); AreaSphere->SetCollisionResponseToChannel(ECollisionChannel::ECC_Pawn, ECollisionResponse::ECR_Overlap); + AreaSphere->OnComponentBeginOverlap.AddDynamic(this, &AWeapon::OnSphereOverlap); + } + + if (PickupWidget) + { + PickupWidget->SetVisibility(false); } } - +void AWeapon::OnSphereOverlap(UPrimitiveComponent* OverlappedComponent, + AActor* OtherActor, + UPrimitiveComponent* OtherComp, + int32 OtherBodyIndex, + bool bFromSweep, + const FHitResult& SweepResult) +{ + ABlasterCharacter* BlasterCharacter = Cast(OtherActor); + if (BlasterCharacter && PickupWidget) + { + PickupWidget->SetVisibility(true); + } +} diff --git a/Source/Blaster/Weapon/Weapon.h b/Source/Blaster/Weapon/Weapon.h index eb75805..600648d 100644 --- a/Source/Blaster/Weapon/Weapon.h +++ b/Source/Blaster/Weapon/Weapon.h @@ -19,15 +19,24 @@ UCLASS() class BLASTER_API AWeapon : public AActor { GENERATED_BODY() - -public: + +public: AWeapon(); protected: virtual void BeginPlay() override; - -private: + UFUNCTION() + virtual void OnSphereOverlap( + UPrimitiveComponent* OverlappedComponent, + AActor* OtherActor, + UPrimitiveComponent* OtherComp, + int32 OtherBodyIndex, + bool bFromSweep, + const FHitResult& SweepResult + ); + +private: UPROPERTY(VisibleAnywhere, Category="Weapon Properties") USkeletalMeshComponent* WeaponMesh; @@ -36,8 +45,9 @@ private: UPROPERTY(VisibleAnywhere) EWeaponState WeaponState; - -public: + UPROPERTY(VisibleAnywhere, Category="Weapon Properties") + class UWidgetComponent* PickupWidget; +public: };