49 lines
1.3 KiB
C#
49 lines
1.3 KiB
C#
using UnityEngine;
|
|
|
|
public class BlackjackDialogHudFix : MonoBehaviour
|
|
{
|
|
[Header("Anchor")]
|
|
public Transform speakerAnchor; // 후크 기준 위치
|
|
public Camera targetCamera; // 비워두면 Camera.main 사용
|
|
|
|
[Header("Panel Check")]
|
|
public GameObject dialoguePanel; // DialoguePanel 넣기
|
|
public bool onlyWhenPanelActive = true;
|
|
|
|
[Header("Placement")]
|
|
public float chestHeight = 2.0f;
|
|
public float forwardOffset = 0.7f;
|
|
public float lateralOffset = 0f;
|
|
|
|
private void LateUpdate()
|
|
{
|
|
if (speakerAnchor == null)
|
|
return;
|
|
|
|
if (onlyWhenPanelActive && dialoguePanel != null && !dialoguePanel.activeInHierarchy)
|
|
return;
|
|
|
|
Camera cam = targetCamera != null ? targetCamera : Camera.main;
|
|
|
|
if (cam == null)
|
|
return;
|
|
|
|
Vector3 toCam = cam.transform.position - speakerAnchor.position;
|
|
toCam.y = 0f;
|
|
|
|
if (toCam.sqrMagnitude < 0.0001f)
|
|
return;
|
|
|
|
Vector3 dir = toCam.normalized;
|
|
Vector3 right = Vector3.Cross(Vector3.up, dir).normalized;
|
|
|
|
Vector3 chestWorld = speakerAnchor.position + Vector3.up * chestHeight;
|
|
|
|
transform.position =
|
|
chestWorld +
|
|
dir * forwardOffset +
|
|
right * lateralOffset;
|
|
|
|
transform.rotation = Quaternion.LookRotation(-dir);
|
|
}
|
|
} |