Serial port input is making the game slower
Hi, I am using serial port input to move a player in the z axis only. But when I am using this code the game is getting too slow. Please Help.
using UnityEngine;
using System.Collections;
using System.IO.Ports;
using System;
public class sensorp : MonoBehaviour {
SerialPort serial = new SerialPort("COM3",115200);
void Update ()
{
Application.targetFrameRate = 20;
if (!serial.IsOpen) {
serial.Open ();
}
string s = serial.ReadLine ();
string[] mystring = s.Split (';');
string axX = mystring [0];
float con=0.0f;
float converted = float.Parse (axX);
if (converted > 0.5) {
con = 1.0f;
}
else if (converted < -0.5) {
con = -1.0f;
}
this.transform.Translate (con*Time.deltaTime*200f,0f,0f);
Debug.Log (converted);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612094449im_/https://answers.unity.com/themes/thub/images/avi.jpg)