FollowCameraPosition.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using UnityEngine;
  2. namespace ARLocation.Utils
  3. {
  4. public class FollowCameraPosition : MonoBehaviour
  5. {
  6. private Transform mainCameraTransform;
  7. public float Height = 1.4f;
  8. public bool UseARLocationConfig = true;
  9. public Transform UseGameObjectHeight;
  10. private float configY;
  11. private bool useGOHeight;
  12. // Use this for initialization
  13. void Start()
  14. {
  15. if (Camera.main != null) mainCameraTransform = Camera.main.transform;
  16. configY = -ARLocation.Config.InitialGroundHeightGuess;
  17. useGOHeight = UseGameObjectHeight != null;
  18. }
  19. // Update is called once per frame
  20. void Update()
  21. {
  22. var cameraPos = mainCameraTransform.position;
  23. var y = useGOHeight ? UseGameObjectHeight.position.y : (UseARLocationConfig ? (cameraPos.y + configY) : (cameraPos.y - Height));
  24. var transform1 = transform;
  25. transform1.position = new Vector3(
  26. cameraPos.x,
  27. y,
  28. cameraPos.z
  29. );
  30. }
  31. }
  32. }