using UnityEngine; using TMPro; public class ArtworkLabel : MonoBehaviour { public TMP_Text titleText; public TMP_Text artistText; public bool alwaysVisible = true; float _target = 1f, _current = 0f; Camera _cam; void Start() { _cam = Camera.main; _current = _target = alwaysVisible ? 1f : 0f; SetAlpha(_current); } public void SetText(string title, string artist) { if (titleText) titleText.text = title ?? ""; if (artistText) artistText.text = artist ?? ""; } public void Show() => _target = 1f; public void Hide() => _target = alwaysVisible ? 1f : 0f; void Update() { if (_cam) { var d = _cam.transform.position - transform.position; d.y = 0; if (d.sqrMagnitude > 0.001f) transform.rotation = Quaternion.LookRotation(-d); } _current = Mathf.MoveTowards(_current, _target, 4f * Time.deltaTime); SetAlpha(_current); } void SetAlpha(float a) { if (titleText) { var c = titleText.color; c.a = a; titleText.color = c; } if (artistText) { var c = artistText.color; c.a = a; artistText.color = c; } } }