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:
parent
2a590c3e33
commit
3360ea2031
BIN
Content/Blueprints/Player/BP_MyTempCharacter.uasset
(Stored with Git LFS)
BIN
Content/Blueprints/Player/BP_MyTempCharacter.uasset
(Stored with Git LFS)
Binary file not shown.
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user