VRTK_始终看向相机方法

 public class LookAtMainCamera : MonoBehaviour
    {
        public bool lookAtHeadset = true;

        public Transform target;

        public Vector3 offset = new Vector3(0, 180, 0);

        private void OnEnable()
        {
            if (lookAtHeadset)
            {

                target = VRTK_DeviceFinder.HeadsetTransform();
            }
        }

        public void LookAtTargetOneFrame(Transform tmp, Vector3 customOffeset)
        {
            if (tmp == null) return;
            transform.LookAt(tmp);
            transform.eulerAngles += offset + customOffeset;
            transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, transform.eulerAngles.z);
        }
        public void LookAtTargetOneFrame(Transform tmp)
        {
            if (tmp == null) return;
            transform.LookAt(tmp);
            transform.eulerAngles += offset;
            transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, transform.eulerAngles.z);
        }
        void Update()
        {

            if (target == null && lookAtHeadset)
            {

                target = VRTK_DeviceFinder.HeadsetTransform();
            }

            if (target != null)
            {
                transform.LookAt(target);

                transform.eulerAngles += offset;

                transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, transform.eulerAngles.z);
            }
        }
    }

 

你可能感兴趣的:(VR,相机)