CursorScale.cs 920 B

123456789101112131415161718192021222324252627282930313233
  1. using UnityEngine;
  2. namespace Ximmerse.XR.InputSystems.GazeAndGestureInteraction
  3. {
  4. public class CursorScale : MonoBehaviour
  5. {
  6. #region Property
  7. private Transform Target;
  8. private GameObject CamCursor;
  9. private float ScaleFactor;
  10. private Vector3 OriginScale;
  11. #endregion
  12. #region Unity
  13. private void Start()
  14. {
  15. CamCursor = CursorManager.Instance.CursorGo;
  16. OriginScale = CamCursor.transform.localScale;
  17. Target = CursorManager.Instance.MainCamera;
  18. ScaleFactor = Vector3.Distance(CamCursor.transform.position, Target.position);
  19. }
  20. void Update()
  21. {
  22. float distance = Vector3.Distance(transform.position, Target.position);
  23. Vector3 scale = distance / ScaleFactor * OriginScale;
  24. transform.localScale = scale;
  25. }
  26. #endregion
  27. }
  28. }