Implemented Base World Item Functionality

This commit is contained in:
Rafal Swierczek 2024-04-13 15:46:23 +01:00
parent 3a3c00418a
commit ad8b9abbca
2 changed files with 20 additions and 17 deletions

View File

@ -3,6 +3,8 @@
#include "BaseWorldItem.h"
#include "InventoryComponent.h"
// Sets default values
ABaseWorldItem::ABaseWorldItem()
@ -11,16 +13,12 @@ ABaseWorldItem::ABaseWorldItem()
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void ABaseWorldItem::BeginPlay()
void ABaseWorldItem::Interact()
{
Super::BeginPlay();
APawn* PlayerPawn = GetWorld()->GetFirstPlayerController()->GetPawn();
UInventoryComponent* PlayersInventory = Cast<UInventoryComponent>(PlayerPawn->GetComponentByClass(UInventoryComponent::StaticClass()));
PlayersInventory->AddItem(NewObject<UBaseItem>(GetWorld(), ItemClass));
Destroy();
}
// Called every frame
void ABaseWorldItem::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}

View File

@ -3,23 +3,28 @@
#pragma once
#include "CoreMinimal.h"
#include "BaseItem.h"
#include "EndlessVendetta/InteractionInterface.h"
#include "GameFramework/Actor.h"
#include "BaseWorldItem.generated.h"
UCLASS()
class ENDLESSVENDETTA_API ABaseWorldItem : public AActor
class ENDLESSVENDETTA_API ABaseWorldItem : public AActor, public IInteractionInterface
{
GENERATED_BODY()
// ---------------------- Attributes --------------------------
UPROPERTY(EditDefaultsOnly, Category = "Item")
TSubclassOf<UBaseItem> ItemClass;
// ---------------------- Methods -----------------------------
protected:
void Interact() override;
public:
// Sets default values for this actor's properties
ABaseWorldItem();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
};