/** * Ardity (Serial Communication for Arduino + Unity) * Author: Daniel Wilches * * This work is released under the Creative Commons Attributions license. * https://creativecommons.org/licenses/by/2.0/ */ using UnityEngine; using System.Collections; /** * Sample for reading using polling by yourself. In case you are fond of that. */ public class SampleUserPolling_JustRead : MonoBehaviour { public SerialController serialController; // Initialization void Start() { serialController = GameObject.Find("SerialController").GetComponent(); } // Executed each frame void Update() { string message = serialController.ReadSerialMessage(); if (message == null) return; // Check if the message is plain data or a connect/disconnect event. if (ReferenceEquals(message, SerialController.SERIAL_DEVICE_CONNECTED)) Debug.Log("Connection established"); else if (ReferenceEquals(message, SerialController.SERIAL_DEVICE_DISCONNECTED)) Debug.Log("Connection attempt failed or disconnection detected"); else Debug.Log("Message arrived: " + message); } }