AttachBikeToHead.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using Valve.VR;
  6. public class AttachBikeToHead : MonoBehaviour
  7. {
  8. public Transform playerTransform;
  9. public Transform cameraTransform;
  10. public Transform bikeTransform;
  11. public float headHeihgt = 1.4f;
  12. public SteamVR_Action_Boolean resetAction;
  13. private float initialBikeY;
  14. // Start is called before the first frame update
  15. void Start()
  16. {
  17. //initialBikeY = bikeTransform.position.y;
  18. ResetPositionAndRotation();
  19. }
  20. private void ResetPositionAndRotation()
  21. {
  22. //bikeTransform.position = new Vector3(playerTransform.position.x, initialBikeY, playerTransform.position.z);
  23. //bikeTransform.rotation = playerTransform.rotation;
  24. //resetAction.AddOnStateUpListener(OnStateUp, SteamVR_Input_Sources.Any);
  25. playerTransform.localPosition = new Vector3(0f, 1.32f, -0.8f);
  26. playerTransform.localRotation = Quaternion.Euler(Vector3.zero);
  27. cameraTransform.position = playerTransform.position;
  28. cameraTransform.rotation = playerTransform.rotation;
  29. }
  30. private void OnStateUp(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource)
  31. {
  32. ResetPositionAndRotation();
  33. }
  34. }