Updated InventoryComponent & TempCharacter

Made it so the buy system is universal meaning any devs will not have to keep adding more if statements just to set the items price. It can all be done in editor now and it all handles itself in the code.
This commit is contained in:
MH261677 2022-11-18 14:53:22 +00:00
parent 220b21f2ca
commit 811856b219
3 changed files with 6 additions and 7 deletions

View File

@ -60,7 +60,7 @@ bool UInventoryComponent::Remove(class UBaseItem* BaseItem)
return false;
}
UBaseItem* UInventoryComponent::GetItem(int32 Index)
UBaseItem* UInventoryComponent::GetItem(int Index)
{
return Items[Index];
}

View File

@ -40,5 +40,5 @@ public:
TArray<class UBaseItem*> Items; // The items currently in the inventory
UFUNCTION(BlueprintCallable, Category= "Inventory")
class UBaseItem* GetItem(int32 Index);
class UBaseItem* GetItem(int Index);
};

View File

@ -41,6 +41,8 @@ void ATempCharacter::RightMoveInput(float Axis)
void ATempCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
UE_LOG(LogTemp, Warning, TEXT("Gold: %d"),GoldBalance);
}
// Gives the character the functionality
@ -81,14 +83,11 @@ void ATempCharacter::LineTraceLogic()
}
if(OutHit.GetActor()->FindComponentByClass<UInventoryComponent>())
{
if(GoldBalance >= 100)
if(GoldBalance >= OutHit.GetActor()->FindComponentByClass<UInventoryComponent>()->GetItem(0)->ItemCostPrice)
{
GoldBalance -= 100;
GoldBalance -= OutHit.GetActor()->FindComponentByClass<UInventoryComponent>()->GetItem(0)->ItemCostPrice;
Inventory->AddItem(OutHit.GetActor()->FindComponentByClass<UInventoryComponent>()->GetItem(0));
//Inventory->AddItem(Cast<UBaseItem>(OutHit.GetActor()));
//Inventory->AddItem(OutHit.GetActor()->Get("HealingJelly"));
UE_LOG(LogTemp, Display, TEXT("Item Purchased"));
}
if(GoldBalance <= 0)
{