quantum-space-buddies/QSB/ConversationSync/CameraFacingBillboard.cs

30 lines
763 B
C#
Raw Normal View History

2021-09-27 15:54:15 +00:00
using UnityEngine;
public class CameraFacingBillboard : MonoBehaviour
{
private OWCamera _activeCam;
private void Awake()
=> GlobalMessenger<OWCamera>.AddListener("SwitchActiveCamera", OnSwitchActiveCamera);
private void Start()
{
_activeCam = Locator.GetActiveCamera();
UpdateRotation();
}
private void OnDestroy()
=> GlobalMessenger<OWCamera>.RemoveListener("SwitchActiveCamera", OnSwitchActiveCamera);
private void OnSwitchActiveCamera(OWCamera activeCamera)
{
_activeCam = activeCamera;
UpdateRotation();
}
2021-10-29 22:00:13 +00:00
private void LateUpdate()
2021-09-27 15:54:15 +00:00
=> UpdateRotation();
private void UpdateRotation()
=> transform.LookAt(transform.position + (_activeCam.transform.rotation * Vector3.forward), _activeCam.transform.rotation * Vector3.up);
}