PolarListener.cs 967 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using UnityEngine;
  3. public class PolarListener : MonoBehaviour
  4. {
  5. private UdpConnection connection;
  6. public int port = 9099;
  7. public String ipAddress = "0.0.0.0";
  8. private float rotation = 0f;
  9. public float divisionValue = 60f;
  10. private void Start()
  11. {
  12. connection = new UdpConnection(ipAddress, port, onAccData);
  13. connection.Listen();
  14. }
  15. private void OnGUI()
  16. {
  17. GUI.TextField(new Rect(10,10, 100, 20), $"{rotation}");
  18. }
  19. private void onAccData(AccData data)
  20. {
  21. //Debug.Log(data.Timestamp);
  22. rotation = data.Values[0].y / divisionValue;
  23. Debug.Log($"Rotate {data.Values[0].y} degrees");
  24. //transform.RotateAround(transform.position, Vector3.forward, data.Values[0].y);
  25. }
  26. private void Update()
  27. {
  28. transform.rotation = Quaternion.Euler(0,90,rotation);
  29. }
  30. private void OnDestroy()
  31. {
  32. connection.StopListening();
  33. }
  34. }