Created
November 23, 2023 22:36
-
-
Save PatHightree/06ad1112581c7303f2c9ed42665b6309 to your computer and use it in GitHub Desktop.
Script to attach an object to the HMD and update the pos/rot just before rendering
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.InputSystem; | |
public class HeadAttach : MonoBehaviour | |
{ | |
public Transform Target; | |
public InputAction HmdPosition; | |
public InputAction HmdRotation; | |
private void Awake() | |
{ | |
HmdPosition.Enable(); | |
HmdRotation.Enable(); | |
} | |
void OnEnable() | |
{ | |
Application.onBeforeRender += ApplicationOnBeforeRender; | |
} | |
private void OnDisable() | |
{ | |
Application.onBeforeRender -= ApplicationOnBeforeRender; | |
} | |
private void ApplicationOnBeforeRender() | |
{ | |
Target.position = HmdPosition.ReadValue<Vector3>(); | |
Target.rotation = HmdRotation.ReadValue<Quaternion>(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment