2026-06-19 UI, UI로직
This commit is contained in:
65
Assets/My project/Dialogue Scripts/UI/DialogueBillboard.cs
Normal file
65
Assets/My project/Dialogue Scripts/UI/DialogueBillboard.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class DialogueBillboard : MonoBehaviour
|
||||
{
|
||||
[Header("Target")]
|
||||
[SerializeField] private Transform target;
|
||||
[SerializeField] private Camera targetCamera;
|
||||
|
||||
[Header("Position")]
|
||||
[SerializeField] private Vector3 offset = new Vector3(0f, 2f, 0f);
|
||||
|
||||
[Header("Look At Camera")]
|
||||
[SerializeField] private bool faceCamera = true;
|
||||
[SerializeField] private bool lockYAxis = false;
|
||||
[SerializeField] private bool rotate180AfterLookAt = true;
|
||||
|
||||
public Transform Target => target;
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
if (target == null)
|
||||
return;
|
||||
|
||||
transform.position = target.position + offset;
|
||||
|
||||
if (!faceCamera)
|
||||
return;
|
||||
|
||||
if (targetCamera == null)
|
||||
targetCamera = Camera.main;
|
||||
|
||||
if (targetCamera == null)
|
||||
return;
|
||||
|
||||
Vector3 lookPosition = targetCamera.transform.position;
|
||||
|
||||
if (lockYAxis)
|
||||
lookPosition.y = transform.position.y;
|
||||
|
||||
transform.LookAt(lookPosition);
|
||||
|
||||
if (rotate180AfterLookAt)
|
||||
transform.Rotate(0f, 180f, 0f);
|
||||
}
|
||||
|
||||
public void SetTarget(Transform newTarget)
|
||||
{
|
||||
target = newTarget;
|
||||
}
|
||||
|
||||
public void ClearTarget()
|
||||
{
|
||||
target = null;
|
||||
}
|
||||
|
||||
public void SetCamera(Camera newCamera)
|
||||
{
|
||||
targetCamera = newCamera;
|
||||
}
|
||||
|
||||
public void SetOffset(Vector3 newOffset)
|
||||
{
|
||||
offset = newOffset;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user