SW 중심대학 OSS GIT 서버 박건태, 이승준, 고기완, 이준호 새로운 배포
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.1 KiB

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