This repository has been archived on 2025-04-28. You can view files and clone it, but cannot push or open issues or pull requests.
ARPlusSystem/ARPlusSystem-250418/Assets/ARLocation/Scripts/Utils/FollowCameraPosition.cs

45 lines
1.1 KiB
C#
Raw Normal View History

using UnityEngine;
namespace ARLocation.Utils
{
public class FollowCameraPosition : MonoBehaviour
{
private Transform mainCameraTransform;
public float Height = 1.4f;
public bool UseARLocationConfig = true;
public Transform UseGameObjectHeight;
private float configY;
private bool useGOHeight;
// Use this for initialization
void Start()
{
if (Camera.main != null) mainCameraTransform = Camera.main.transform;
configY = -ARLocation.Config.InitialGroundHeightGuess;
useGOHeight = UseGameObjectHeight != null;
}
// Update is called once per frame
void Update()
{
var cameraPos = mainCameraTransform.position;
var y = useGOHeight ? UseGameObjectHeight.position.y : (UseARLocationConfig ? (cameraPos.y + configY) : (cameraPos.y - Height));
var transform1 = transform;
transform1.position = new Vector3(
cameraPos.x,
y,
cameraPos.z
);
}
}
}