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 "Interaction.h"
|
||||||
|
|
||||||
|
#include "Chaos/BoundingVolumeUtilities.h"
|
||||||
#include "Components/WidgetComponent.h"
|
#include "Components/WidgetComponent.h"
|
||||||
|
|
||||||
|
|
||||||
@ -32,11 +33,16 @@ void AInteraction::OnInteract()
|
|||||||
{
|
{
|
||||||
CurrentWidget = CreateWidget<UUserWidget>(GetWorld(), Widget);
|
CurrentWidget = CreateWidget<UUserWidget>(GetWorld(), Widget);
|
||||||
CurrentWidget->AddToViewport(0);
|
CurrentWidget->AddToViewport(0);
|
||||||
|
//handles the widget dissapearing from the viewport
|
||||||
FTimerHandle WidgetTimer;
|
FTimerHandle WidgetTimer;
|
||||||
GetWorldTimerManager().SetTimer(WidgetTimer, this, &AInteraction::RemoveWidget, WaitTimer, false);
|
GetWorldTimerManager().SetTimer(WidgetTimer, this, &AInteraction::RemoveWidget, WaitTimer, false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AInteraction::RemoveWidget()
|
void AInteraction::RemoveWidget()
|
||||||
{
|
{
|
||||||
|
bisDisabled = true;
|
||||||
CurrentWidget->RemoveFromViewport();
|
CurrentWidget->RemoveFromViewport();
|
||||||
|
UE_LOG(LogTemp, Display, TEXT("setting isDisabled to true"));
|
||||||
|
|
||||||
}
|
}
|
@ -27,10 +27,15 @@ public:
|
|||||||
TSubclassOf<UUserWidget> Widget;
|
TSubclassOf<UUserWidget> Widget;
|
||||||
|
|
||||||
virtual void OnInteract();
|
virtual void OnInteract();
|
||||||
|
|
||||||
virtual void RemoveWidget();
|
virtual void RemoveWidget();
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
UUserWidget* CurrentWidget;
|
UUserWidget* CurrentWidget;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere)
|
UPROPERTY(EditAnywhere)
|
||||||
float WaitTimer = 8.0f;
|
float WaitTimer = 8.0f;
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
|
bool bisDisabled = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -96,13 +96,36 @@ void ATempCharacter::LineTraceLogic()
|
|||||||
UE_LOG(LogTemp, Display, TEXT("Not Enough Gold"));
|
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()))
|
if (AInteraction* MyInteractable = Cast<AInteraction>(OutHit.GetActor()))
|
||||||
{
|
{
|
||||||
DrawDebugLine(GetWorld(), Start, End, FColor::Green, false, 1.0f);
|
DrawDebugLine(GetWorld(), Start, End, FColor::Green, false, 1.0f);
|
||||||
MyInteractable->OnInteract();
|
MyInteractable->OnInteract();
|
||||||
|
UE_LOG(LogTemp, Display, TEXT("OnInteract activated"));
|
||||||
UE_LOG(LogTemp, Display, TEXT("HIT: %s"), *OutHit.GetActor()->GetName());
|
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)
|
void ATempCharacter::UseItem(class UBaseItem* Item)
|
||||||
|
@ -38,6 +38,7 @@ public:
|
|||||||
UPROPERTY(EditAnyWhere)
|
UPROPERTY(EditAnyWhere)
|
||||||
float TraceDistance = 200;
|
float TraceDistance = 200;
|
||||||
|
|
||||||
|
void InputDisabler();
|
||||||
void LineTraceLogic();
|
void LineTraceLogic();
|
||||||
|
|
||||||
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category= "Health")
|
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category= "Health")
|
||||||
@ -52,4 +53,5 @@ public:
|
|||||||
//Using the item in the inventory
|
//Using the item in the inventory
|
||||||
UFUNCTION(BlueprintCallable, Category= "Items")
|
UFUNCTION(BlueprintCallable, Category= "Items")
|
||||||
void UseItem(class UBaseItem* Item); // Overriding the BaseItem Class
|
void UseItem(class UBaseItem* Item); // Overriding the BaseItem Class
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user