title: Timeout Exception when trying to connect Arduino to Unity
body: <p>I instantly get Timeout Exception when i press play on Unity
  This is my Unity code 'comment to skip error on stackoverflow comment to skip error on stackoverflow'</p>
  
  <pre><code>    using UnityEngine;
  using System.Collections;
  using System.IO.Ports;
  using System.Threading;
  
  [RequireComponent(typeof(Controller2D))]   
  
  public class Player : MonoBehaviour {
  
      public float moveSpeed = 6;
      public float gravity = -20;
      public float jumpDistance = 8;
      Vector3 moveDistance;
  
      SerialPort sp = new SerialPort("COM7", 9600);
  
      Controller2D controller;    
      void Start() {
          controller = GetComponent&lt;Controller2D&gt;();  
          sp.Open();
          sp.ReadTimeout = 100;
      }
  
      void Update() {
          if (sp.IsOpen) {
              try {
                  print(sp.ReadByte());
  
              }
              catch (System.Exception) {
  
                  throw;
              }
          }
  
          if (controller.collisions.above || controller.collisions.below) {   
              moveDistance.y = 0;
          }
          if (Input.GetKeyDown(KeyCode.Space) || sp.ReadByte() == 1 &amp;&amp; controller.collisions.below) {   
              moveDistance.y = jumpDistance;
          }
          Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));  
  
  
          moveDistance.x = input.x * moveSpeed;   
          moveDistance.y += gravity * Time.deltaTime;     
          controller.Move(moveDistance * Time.deltaTime);     
  
      }
  
  
  }
  </code></pre>
  
  <p>Arduino code</p>
  
  <pre><code>const int buttonPin01 = 6;
  const int buttonPin02 = 7;
  const int buttonPin03 = 8;
  
  void setup() {
    Serial.begin(9600);
  
    pinMode(buttonPin01, INPUT);
    pinMode(buttonPin02, INPUT);
    pinMode(buttonPin03, INPUT);
  
    digitalWrite(buttonPin01, HIGH);
    digitalWrite(buttonPin02, HIGH);
    digitalWrite(buttonPin03, HIGH);
  
  
  }
  
  void loop() {
    if (digitalRead(buttonPin01) == LOW){
      Serial.write(1);
      Serial.flush();
      delay(10);
    }
  
    if (digitalRead(buttonPin02) == LOW){
      Serial.write(2);
      Serial.flush();
      delay(10);
    }
  
    if (digitalRead(buttonPin03) == LOW){
      Serial.write(3);
      Serial.flush();
      delay(10);
    }
  
  }
  </code></pre>
  
  <p>My error</p>
  
  <pre><code>TimeoutException: The operation has timed out.
  System.IO.Ports.WinSerialStream.Read (System.Byte[] buffer, System.Int32 offset, System.Int32 count) (at &lt;3845a180c26b4889bc2d47593a665814&gt;:0)
  System.IO.Ports.SerialPort.read_byte () (at &lt;3845a180c26b4889bc2d47593a665814&gt;:0)
  System.IO.Ports.SerialPort.ReadByte () (at &lt;3845a180c26b4889bc2d47593a665814&gt;:0)
  (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPort.ReadByte()
  Player.Update () (at Assets/Script/Player.cs:35)
  </code></pre>
  
  <p>I have tried changing the delay to a higher and lower value, changing the baud speed.
  Would appreciate it if someone could identify this problem ty</p>