12345678910111213141516171819202122232425262728293031323334353637383940 |
- 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 void Start()
- {
- 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");
- //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();
- }
- }
|