1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- using System;
- using UnityEngine;
- public class PolarListener : MonoBehaviour
- {
- private UdpConnection connection;
- public int port = 9099;
- public String ipAddress = "0.0.0.0";
- private float rotation = 0f;
- public float divisionValue = 60f;
- private BicycleController bicycleController;
- private void Start()
- {
- bicycleController = GetComponent<BicycleController>();
- connection = new UdpConnection(ipAddress, port, OnAccData);
- connection.Listen();
- }
- private void OnGUI()
- {
- GUI.TextField(new Rect(10,10, 100, 20), $"{rotation}");
- }
- private void OnAccData(AccData data)
- {
- //Debug.Log(data.Timestamp);
- rotation = data.Values[0].y / divisionValue;
- Debug.Log($"Rotate {data.Values[0].y} degrees");
- bicycleController.SetSteeringAngle(-rotation);
- //transform.RotateAround(transform.position, Vector3.forward, data.Values[0].y);
- }
- /*private void Update()
- {
- transform.rotation = Quaternion.Euler(0,90,rotation);
- }*/
- private void OnDestroy()
- {
- connection.StopListening();
- }
- }
|