CubeLabel.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. // /******************************************************************************
  2. // * File: CubeLabel.cs
  3. // * Copyright (c) 2023 Qualcomm Technologies, Inc. and/or its subsidiaries. All rights reserved.
  4. // *
  5. // *
  6. // ******************************************************************************/
  7. using UnityEngine;
  8. namespace QCHT.Samples.Proximal
  9. {
  10. public class CubeLabel : MonoBehaviour
  11. {
  12. [SerializeField] private GameObject label;
  13. [SerializeField] private Collider objectCollider;
  14. [SerializeField] private float labelYOffset = 0.01f;
  15. public void ShowLabel(bool show) => label.SetActive(show);
  16. private void LateUpdate()
  17. {
  18. if (ReferenceEquals(objectCollider, null)) return;
  19. UpdateLabelPosition();
  20. }
  21. private void UpdateLabelPosition()
  22. {
  23. var bounds = objectCollider.bounds;
  24. var center = bounds.center;
  25. var size = bounds.size;
  26. label.transform.position = center + new Vector3(0, size.y / 2 + labelYOffset, 0);
  27. }
  28. }
  29. }