Updated TempCharacter,TempCharacter.cpp

Gave a max inventory slots of 5 for testing purposes and Refactored code in TempCharacter.cpp
This commit is contained in:
MH261677 2022-11-29 12:55:46 +00:00
parent 2a590c3e33
commit 3360ea2031
2 changed files with 7 additions and 5 deletions

Binary file not shown.

View File

@ -77,16 +77,18 @@ void ATempCharacter::LineTraceLogic()
bHit = GetWorld()->LineTraceSingleByChannel(OutHit, Start, End, ECC_Visibility, TraceParams); bHit = GetWorld()->LineTraceSingleByChannel(OutHit, Start, End, ECC_Visibility, TraceParams);
if (bHit) if (bHit)
{ {
//we store the GetItem function from InventoryComponent into ItemArray variable
auto ItemArray = OutHit.GetActor()->FindComponentByClass<UInventoryComponent>()->GetItem(0);
if(OutHit.GetActor() == nullptr) if(OutHit.GetActor() == nullptr)
{ {
return; return;
} }
if(OutHit.GetActor()->FindComponentByClass<UInventoryComponent>()) if(OutHit.GetActor()->FindComponentByClass<UInventoryComponent>())
{ {
if(GoldBalance >= OutHit.GetActor()->FindComponentByClass<UInventoryComponent>()->GetItem(0)->ItemCostPrice) if(GoldBalance >= ItemArray->ItemCostPrice)
{ {
GoldBalance -= OutHit.GetActor()->FindComponentByClass<UInventoryComponent>()->GetItem(0)->ItemCostPrice; GoldBalance -= ItemArray->ItemCostPrice;
Inventory->AddItem(OutHit.GetActor()->FindComponentByClass<UInventoryComponent>()->GetItem(0)); Inventory->AddItem(ItemArray);
UE_LOG(LogTemp, Display, TEXT("Item Purchased")); UE_LOG(LogTemp, Display, TEXT("Item Purchased"));
} }
if(GoldBalance <= 0) if(GoldBalance <= 0)