# Unity and arduino processing

This question relates to this link: https://www.freetronics.com.au/blogs/news/6537043-experimenting-with-unity-processing-and-arduino#.W2-SFs4zbIU Does anyone have any idea how I would begin doing this? I cannot find the tutorial or code that relates to this. I have a cube on unity that changes colour and texture according to the input from a force sensing resistor. How would I get the cube to react in this way (as in the video)? Any assistance will be appreciated

In this video, a flexiforce sensor is housed in a cube. When the user presses the sensor, a cube on Unity reacts in the same manner that the real cube is squeezed; its basically a virtual version of what is happening to the cube in real life

• How about this? I didn't get to the bottom but apparently Unity ha a SerialPort class to handle that alanzucconi.com/2015/10/07/how-to-integrate-arduino-with-unity – JoulinRouge Aug 12 '18 at 9:30
• I'm unable to view the link & video in their entirety from my current net connection. To make your question easier to understand for users in similar situations, it would help to edit your question to describe what you mean by "doing this" or "react in this way" in words. This also makes your question more searchable for users with relevant expertise, or users trying to solve similar problems. – DMGregory Aug 12 '18 at 12:18
• I have edited the question to add some more information to my query – user19964 Aug 13 '18 at 1:37
• So just to clarify: you have the cube/unity connection working, you just want to figure out how to change the cube's shape? – The Guy with The Hat Aug 14 '18 at 23:11
• Yes, I have the cube/unity and arduino part working, I just want to know how to make the cube change shape as the force is exerted on the cube. Currently the cube changes color and texture as different levels of force is exerted on it – user19964 Aug 14 '18 at 23:17

This works well:

     using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO.Ports;
using System.IO;
public class arduino : MonoBehaviour
{

public SerialPort sp = new SerialPort("\\\\.\\COM5", 9600);// Com port and the baud rate of the arduino
Material m_Material;
GameObject Sphere;

void Awake()
{
Sphere = GameObject.FindWithTag("Player");
m_Material = GameObject.FindWithTag("Player").GetComponent<Renderer>().material;
}
void Start()
{
if (!sp.IsOpen)
{
sp.Open(); // Open
}

}

// Update is called once per frame
void Update()
{
if (sp.IsOpen)
{ // Check to see if the serial port is open
try
{

//string portreading = sp.ReadLine(); // get the string output of the serial port
float amount = float.Parse(value);

if ((amount > 251f))
{
m_Material.color = Color.red;
Renderer _rend = Sphere.GetComponent<Renderer>();
Sphere.GetComponent<Renderer>().material = _rend.material;
Sphere.transform.localScale = new Vector3( 2f, 0.03f*amount, 2f);
//Sphere.transform.position = new Vector3(2f, 2f , 2f);
}
else
{
m_Material.color = Color.white;
Sphere.transform.localScale = new Vector3(2f, 10f, 8f);

}
}
catch (System.Exception)
{

}
}
}