I did a test connecting Arduino and Unity with the help of Processing and a Open Sound Control library. When I am pushing the Flexi Force sensor the values affect a cube within Unity. To get this setup do the following:
Load the Standard Firmdata on to your Arduino. Check out a full Arduino + Processing tutorial to get the setup.
Download the oscP5 processing library and put it in your Processing sketch folder in the folder libraries.
Initialize oscP5 library and broadcast data to port 12000. The port Unity will listen to.
Add the remote location to listen to on port 3200. If Unity would broadcast event in this example, the broadcast port would be set to 3200. Initialise Arduino to be used later on.
myRemoteLocation = new NetAddress("127.0.0.1",3200);
arduino = new Arduino(this, Arduino.list(), 57600);
In the draw function we read the analoge pin 0 to get sensor values from the Flexi Force sensor. Set the OSC message to flexiforce. Unity will listen to this label. Add the message of the sensor value into the osc message with add method. This method can take numbers, strings and byte data.
OscMessage oscMess = new OscMessage("/flexiforce");
In Unity you can import the Osc.cs and UDPPacketIO.cs to broadcast and listen to UDP data.
Set up the corresponding host and ports in your Unity script.
public var SendToPort : int = 3200;
public var ListenerPort : int = 12000;
udp.init(OSCHost, SendToPort, ListenerPort);
handler = GetComponent("Osc");
In the receiving method you can print out the label and message values. In this case the sensor value from the Flexi Force. The cube will change width when getting a new value from Processing.
Debug.Log("Event name: " + Osc.OscMessageToString(oscMessage));
Debug.Log("Event data: " + oscMessage.Values);
var myCube = GameObject.Find("Cube");
var boxWidth:int = 8 - ( oscMessage.Values);
myCube.transform.localScale = Vector3(boxWidth,5,5);