PolarListener.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 BicycleController bicycleController;
  11. private void Start()
  12. {
  13. bicycleController = GetComponent<BicycleController>();
  14. connection = new UdpConnection(ipAddress, port, OnAccData);
  15. connection.Listen();
  16. }
  17. private void OnGUI()
  18. {
  19. GUI.TextField(new Rect(10,10, 100, 20), $"{rotation}");
  20. }
  21. private void OnAccData(AccData data)
  22. {
  23. //Debug.Log(data.Timestamp);
  24. rotation = data.Values[0].y / divisionValue;
  25. Debug.Log($"Rotate {data.Values[0].y} degrees");
  26. bicycleController.SetSteeringAngle(-rotation);
  27. //transform.RotateAround(transform.position, Vector3.forward, data.Values[0].y);
  28. }
  29. /*private void Update()
  30. {
  31. transform.rotation = Quaternion.Euler(0,90,rotation);
  32. }*/
  33. private void OnDestroy()
  34. {
  35. connection.StopListening();
  36. }
  37. }