안내 UI("E를 눌러 상호작용")는 콜리전 범위 진입/이탈로 켜지고 꺼지는데 편지 내용 위젯은 E키로 뜨고 닫힌다.
이 둘은 독립적으로 동작하고 있었고 그래서 편지가 펼쳐진 상태에서도 안내 UI가 겹쳐서 그 위에 계속 떠있는 문제가 생겼다
1. DarkLetter.h에 위젯 관련 변수 추가
class ULetterWidget; // 전방 선언
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Letter")
TSubclassOf<ULetterWidget> LetterWidgetClass;
UPROPERTY()
ULetterWidget* LetterWidgetInstance;
2. ActivateItem을 토글 로직으로 구현
void ADarkLetter::ActivateItem(AActor* Activator)
{
if (Activator && Activator->ActorHasTag("Player"))
{
ATheRoomCharacter* PlayerCharacter = Cast<ATheRoomCharacter>(Activator);
if (!PlayerCharacter) return;
if (LetterWidgetInstance)
{
// 이미 떠있음 → 닫기
LetterWidgetInstance->RemoveFromParent();
LetterWidgetInstance = nullptr;
PlayerCharacter->ShowInteraction(); // 안내 UI 다시 켜기
}
else if (LetterWidgetClass)
{
// 안 떠있음 → 띄우기
LetterWidgetInstance = CreateWidget<ULetterWidget>(GetWorld(), LetterWidgetClass);
LetterWidgetInstance->AddToViewport();
PlayerCharacter->HideInteraction(); // 안내 UI 끄기
}
}
}
Activator는 AActor* 타입으로 들어오기 때문에 ShowInteraction이나 HideInteraction 같은 캐릭터 전용 함수를 호출하려면 ATheRoomCharacter로 캐스팅하는 과정이 필요하다.
LetterWidgetInstance의 존재 여부로 분기해서 떠있으면 닫고 안내 UI를 켜고, 닫혀있으면 띄우고 안내 UI를 끈다.
에디터에서는 BP_DarkLetter의 LetterWidgetClass 슬롯에 WBP_DarkLetter를 연결해뒀다
'프로젝트 > The Room (방탈출 게임)' 카테고리의 다른 글
| 상호작용하면 열리는 서랍장 만들기 (0) | 2026.06.22 |
|---|---|
| 편지를 읽어야 문이 열리는 시스템 만들기 (0) | 2026.06.22 |
| UMG로 상호작용 안내 위젯 띄우기 (0) | 2026.06.22 |
| Enhanced Input으로 E키 상호작용 연결하기 (0) | 2026.06.22 |
| 인터페이스, Enhanced Input 매핑, UI 연결 (0) | 2026.06.21 |
