Billboard.cs 796 B

123456789101112131415161718192021222324252627282930
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace Imagine.WebAR.Samples
  5. {
  6. public class Billboard : MonoBehaviour
  7. {
  8. [SerializeField] Camera mainCamera;
  9. private enum BillboardMode {Y_UP, ALL_AXES}
  10. [SerializeField] BillboardMode mode = BillboardMode.Y_UP;
  11. void LateUpdate()
  12. {
  13. if (mode == BillboardMode.ALL_AXES){
  14. transform.LookAt(mainCamera.transform);
  15. }
  16. else{
  17. transform.LookAt(mainCamera.transform);
  18. var eul = transform.localEulerAngles;
  19. eul.x = 0;
  20. eul.z = 0;
  21. transform.localEulerAngles = eul;
  22. }
  23. transform.Rotate(0, 180, 0);
  24. }
  25. }
  26. }