在此基础上,挂上第三个脚本FollowHeadsetCamera.cs,用于追踪HeadsetCamera。
//FollowHeadsetCamera.cs
using UnityEngine;
public class FollowHeadsetCamera : MonoBehaviour
{
public Transform HeadsetTransform;
public float DepthOffset;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.position = HeadsetTransform.position - HeadsetTransform.forward * DepthOffset;
transform.rotation = HeadsetTransform.rotation;