HeadLockVR.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class HeadLockVR : MonoBehaviour
  5. {
  6. public string lockAxis = "Jump";
  7. bool cameraLocked = false;
  8. Quaternion lockedRotation;
  9. public GameObject parent;
  10. // Start is called before the first frame update
  11. void Start()
  12. {
  13. }
  14. void Update(){
  15. }
  16. // Update is called once per frame
  17. void LateUpdate()
  18. {
  19. Vector3 cameraAngles = Camera.main.transform.localEulerAngles;
  20. Vector3 parentAngles = new Vector3(cameraAngles.x-90, cameraAngles.y-90, cameraAngles.z-90);
  21. parent.transform.eulerAngles = parentAngles;
  22. //target.transform.rotation = Camera.main.transform.rotation * -1;
  23. //target.transform.Rotate(-cameraRotation.x, -cameraRotation.y, -cameraRotation.z);
  24. //Debug.Log(Camera.main.transform.localEulerAngles);
  25. //Camera.main.transform.LookAt(target.transform);
  26. //OVRManager.display.RecenterPose();
  27. //Camera.main.transform.rotation = lockedRotation;
  28. if(Input.GetAxisRaw(lockAxis) != 0){
  29. Debug.Log("Locked Camera");
  30. if(!cameraLocked){
  31. cameraLocked = true;
  32. lockedRotation = Quaternion.identity;
  33. }
  34. Camera.main.transform.rotation = lockedRotation;
  35. }else if(Input.GetAxisRaw(lockAxis) == 0){
  36. cameraLocked = false;
  37. }
  38. }
  39. }