Updated Interaction, TempCharacter.cpp
Created InputDisabler functions to disable player controls when dialouge box stops to start working on merchant
This commit is contained in:
parent
a582a05a59
commit
29c3fdcf09
@ -3,6 +3,7 @@
|
||||
|
||||
#include "Interaction.h"
|
||||
|
||||
#include "Chaos/BoundingVolumeUtilities.h"
|
||||
#include "Components/WidgetComponent.h"
|
||||
|
||||
|
||||
@ -32,11 +33,16 @@ void AInteraction::OnInteract()
|
||||
{
|
||||
CurrentWidget = CreateWidget<UUserWidget>(GetWorld(), Widget);
|
||||
CurrentWidget->AddToViewport(0);
|
||||
//handles the widget dissapearing from the viewport
|
||||
FTimerHandle WidgetTimer;
|
||||
GetWorldTimerManager().SetTimer(WidgetTimer, this, &AInteraction::RemoveWidget, WaitTimer, false);
|
||||
|
||||
}
|
||||
|
||||
void AInteraction::RemoveWidget()
|
||||
{
|
||||
bisDisabled = true;
|
||||
CurrentWidget->RemoveFromViewport();
|
||||
UE_LOG(LogTemp, Display, TEXT("setting isDisabled to true"));
|
||||
|
||||
}
|
@ -27,10 +27,15 @@ public:
|
||||
TSubclassOf<UUserWidget> Widget;
|
||||
|
||||
virtual void OnInteract();
|
||||
|
||||
virtual void RemoveWidget();
|
||||
UPROPERTY()
|
||||
UUserWidget* CurrentWidget;
|
||||
|
||||
UPROPERTY(EditAnywhere)
|
||||
float WaitTimer = 8.0f;
|
||||
|
||||
UPROPERTY()
|
||||
bool bisDisabled = false;
|
||||
};
|
||||
|
||||
|
@ -96,14 +96,37 @@ void ATempCharacter::LineTraceLogic()
|
||||
UE_LOG(LogTemp, Display, TEXT("Not Enough Gold"));
|
||||
}
|
||||
}
|
||||
// if the actor hit has the interaction component/script then it will activate the code
|
||||
|
||||
if (AInteraction* MyInteractable = Cast<AInteraction>(OutHit.GetActor()))
|
||||
{
|
||||
DrawDebugLine(GetWorld(), Start, End, FColor::Green, false, 1.0f);
|
||||
MyInteractable->OnInteract();
|
||||
UE_LOG(LogTemp, Display, TEXT("OnInteract activated"));
|
||||
UE_LOG(LogTemp, Display, TEXT("HIT: %s"), *OutHit.GetActor()->GetName());
|
||||
|
||||
// While loop to check bisDisabled var until it changes to true
|
||||
while (MyInteractable->bisDisabled == false)
|
||||
{
|
||||
if (MyInteractable->bisDisabled == true)
|
||||
{
|
||||
//I am creating a 5 second timer here that then executes the inputdisabler function
|
||||
FTimerHandle TimerHandle;
|
||||
FTimerDelegate TimerDelegate = FTimerDelegate::CreateUObject(this, &ATempCharacter::InputDisabler);
|
||||
GetWorld()->GetTimerManager().SetTimer(TimerHandle, TimerDelegate, 6.0f, false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ATempCharacter::InputDisabler()
|
||||
{
|
||||
UE_LOG(LogTemp, Display, TEXT("Disabling playermovement"));
|
||||
GetWorld()->GetFirstPlayerController()->SetIgnoreLookInput(false);
|
||||
GetWorld()->GetFirstPlayerController()->SetIgnoreMoveInput(true);
|
||||
}
|
||||
|
||||
void ATempCharacter::UseItem(class UBaseItem* Item)
|
||||
{
|
||||
|
@ -38,6 +38,7 @@ public:
|
||||
UPROPERTY(EditAnyWhere)
|
||||
float TraceDistance = 200;
|
||||
|
||||
void InputDisabler();
|
||||
void LineTraceLogic();
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category= "Health")
|
||||
@ -52,4 +53,5 @@ public:
|
||||
//Using the item in the inventory
|
||||
UFUNCTION(BlueprintCallable, Category= "Items")
|
||||
void UseItem(class UBaseItem* Item); // Overriding the BaseItem Class
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user