Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void URInteractComponent::TraceForward(FVector Origin, FVector Direction)
- {
- FHitResult Hit;
- //GameTraceChannel1 is a custom interact trace collision
- bool bHit = GetWorld()->LineTraceSingleByChannel(Hit, Origin, Origin + Direction * InteractRange,
- ECC_GameTraceChannel1,
- FColParam);
- if (bHit)
- {
- AActor* Interactable = Hit.GetActor();
- if (Interactable)
- {
- if (Interactable != FocusedActor)
- {
- if (FocusedActor) //Clear previous focused actor
- {
- IInteractInterface* Interface = Cast<IInteractInterface>(FocusedActor);
- if (Interface)
- {
- Interface->Execute_OnFocusLost(FocusedActor);
- }
- }
- IInteractInterface* Interface = Cast<IInteractInterface>(Interactable);
- if (Interface) //focus on new actor
- {
- Interface->Execute_OnFocus(Interactable);
- }
- }
- FocusedActor = Interactable;
- }
- }
- else
- {
- if (FocusedActor) //Remove focused actor if nothing interactable is hit
- {
- IInteractInterface* Interface = Cast<IInteractInterface>(FocusedActor);
- if (Interface)
- {
- Interface->Execute_OnFocusLost(FocusedActor);
- }
- }
- FocusedActor = nullptr;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement