TestStartScene.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class TestStartScene : MonoBehaviour
  6. {
  7. bool state = true;
  8. Gyroscope gyro;
  9. public Text debug;
  10. private void Start()
  11. {
  12. gyro = Input.gyro;
  13. gyro.enabled = true;
  14. // debug.text = Vector3.zero.ToString();
  15. // transform.eulerAngles = new Vector3(0, 133, 0);
  16. }
  17. private void LateUpdate()
  18. {
  19. if(API_SVR.GetHead()!=null&&state)
  20. {
  21. state = false;
  22. transform.position = API_SVR.GetHead().position;
  23. // transform.eulerAngles = API_SVR.GetHead().eulerAngles;
  24. StartGyroscope();
  25. this.enabled = false;
  26. }
  27. }
  28. /// <summary>
  29. /// 调用陀螺仪 来确定物体摆放位置
  30. /// </summary>
  31. public void StartGyroscope()
  32. {
  33. if (SystemInfo.supportsGyroscope)
  34. {
  35. Vector3 a = gyro.attitude.eulerAngles;
  36. // a = new Vector3(-a.x, -a.y, a.z);
  37. Debug.Log(a);
  38. //transform.eulerAngles = a;
  39. transform.eulerAngles = new Vector3(0, (-a.y+(-a.y+110)), 0);
  40. debug.text = a.ToString();
  41. }
  42. }
  43. }