Billboarder.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /**
  2. * Copyright(c) Live2D Inc. All rights reserved.
  3. *
  4. * Use of this source code is governed by the Live2D Open Software license
  5. * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
  6. */
  7. using UnityEngine;
  8. namespace Live2D.Cubism.Samples.LookAt
  9. {
  10. /// <summary>
  11. /// Forces a <see cref="GameObject"/> to face a camera.
  12. /// </summary>
  13. public class Billboarder : MonoBehaviour
  14. {
  15. /// <summary>
  16. /// Camera to face.
  17. /// </summary>
  18. [SerializeField] public Camera CameraToFace;
  19. #region Unity Event Handling
  20. /// <summary>
  21. /// Called by Unity. Updates facing.
  22. /// </summary>
  23. private void Update()
  24. {
  25. if (CameraToFace.orthographic)
  26. {
  27. transform.LookAt(transform.position - CameraToFace.transform.forward, CameraToFace.transform.up);
  28. }
  29. else
  30. {
  31. transform.LookAt(CameraToFace.transform.position, CameraToFace.transform.up);
  32. }
  33. }
  34. #endregion
  35. }
  36. }