30 lines
790 B
C#
30 lines
790 B
C#
using UnityEngine;
|
|
|
|
namespace Unheimlich.UI
|
|
{
|
|
/// <summary>
|
|
/// Makes UI element always face the main camera.
|
|
/// Commonly used for world-space UI elements like floating words.
|
|
/// </summary>
|
|
public class BillboardUI : MonoBehaviour
|
|
{
|
|
private Transform _cameraTransform;
|
|
|
|
private void Start()
|
|
{
|
|
_cameraTransform = Camera.main.transform;
|
|
|
|
if (_cameraTransform == null)
|
|
Debug.LogWarning($"BillboardUI on {gameObject.name}: Main camera not found!");
|
|
}
|
|
|
|
private void LateUpdate()
|
|
{
|
|
if (_cameraTransform != null)
|
|
{
|
|
transform.LookAt(transform.position + _cameraTransform.rotation * Vector3.forward,
|
|
_cameraTransform.rotation * Vector3.up);
|
|
}
|
|
}
|
|
}
|
|
} |