Updated Book & Gun to be Pickupable by Interact Key

This commit is contained in:
Philip W 2023-05-21 19:06:16 +01:00
parent d17ba9e064
commit 8b87098cf8
4 changed files with 20 additions and 13 deletions

Binary file not shown.

Binary file not shown.

BIN
Content/Levels/Build.umap (Stored with Git LFS)

Binary file not shown.

View File

@ -11,6 +11,7 @@
#include "Components/PawnNoiseEmitterComponent.h"
#include "Blueprint/WidgetBlueprintLibrary.h"
#include "Kismet/KismetMathLibrary.h"
#include "Misc/OutputDeviceNull.h"
// CONSTRUCTOR
@ -130,7 +131,8 @@ void ATempCharacter::Tick(float DeltaTime)
}
if (OutResult.GetActor()->ActorHasTag("Probertium") || OutResult.GetActor()->ActorHasTag("Iroquid")
|| OutResult.GetActor()->ActorHasTag("Azos") || OutResult.GetActor()->ActorHasTag("Eis")
|| OutResult.GetActor()->ActorHasTag("NPC") || OutResult.GetActor()->FindComponentByClass<UInventoryComponent>())
|| OutResult.GetActor()->ActorHasTag("NPC") || OutResult.GetActor()->ActorHasTag("Interactable")
|| OutResult.GetActor()->FindComponentByClass<UInventoryComponent>())
{
CrossHair->SetBrush(UWidgetBlueprintLibrary::MakeBrushFromTexture(InteractableCrossHair));
CrossHair->SetDesiredSizeOverride(FVector2D(43.6, 51.3));
@ -173,9 +175,9 @@ void ATempCharacter::LineTraceLogic()
{
//UE_LOG(LogTemp, Display, TEXT("LineTraceLogic activated"));
ThisCamera = Cast<UCameraComponent>(this->FindComponentByClass<UCameraComponent>());
float GlobalTrace = TraceDistance;
FVector Start = ThisCamera->GetComponentLocation();
FVector End = Start + GlobalTrace * ThisCamera->GetForwardVector();
const float GlobalTrace = TraceDistance;
const FVector Start = ThisCamera->GetComponentLocation();
const FVector End = Start + GlobalTrace * ThisCamera->GetForwardVector();
FCollisionQueryParams TraceParams;
TraceParams.AddIgnoredActor(this);
bHit = GetWorld()->LineTraceSingleByChannel(OutHit, Start, End, ECC_Pawn, TraceParams);
@ -205,10 +207,17 @@ void ATempCharacter::LineTraceLogic()
AddToInventory();
return;
}
if (OutHit.GetActor()->ActorHasTag(TEXT("Interactable")))
{
FOutputDeviceNull AR;
const FString Command = FString::Printf(TEXT("Interact"));
OutHit.GetActor()->CallFunctionByNameWithArguments(*Command, AR, nullptr, true);
return;
}
if (OutHit.GetActor()->FindComponentByClass<UInventoryComponent>())
{
UE_LOG(LogTemp, Display, TEXT("Hit Merchant"));
auto ItemArray = OutHit.GetActor()->FindComponentByClass<UInventoryComponent>()->GetItem(0);
const auto ItemArray = OutHit.GetActor()->FindComponentByClass<UInventoryComponent>()->GetItem(0);
if (GoldBalance >= ItemArray->ItemCostPrice)
{
GoldBalance -= ItemArray->ItemCostPrice;
@ -238,7 +247,7 @@ void ATempCharacter::AddToInventory()
if (OutHit.GetActor()->FindComponentByClass<UInventoryComponent>())
{
UE_LOG(LogTemp, Display, TEXT("Hit Merchant"));
auto ItemArray = OutHit.GetActor()->FindComponentByClass<UInventoryComponent>()->GetItem(0);
const auto ItemArray = OutHit.GetActor()->FindComponentByClass<UInventoryComponent>()->GetItem(0);
if (GoldBalance >= ItemArray->ItemCostPrice)
{
GoldBalance -= ItemArray->ItemCostPrice;
@ -255,8 +264,6 @@ void ATempCharacter::AddToInventory()
void ATempCharacter::InputDisabler()
{
//TURNING OFF CROSSHAIR
CrossHairWidget->SetVisibility(ESlateVisibility::Hidden);
//Set to UI Mode Only