Unity Code
using System.Collections;
using System.Collections.Generics;
using UnityEngine;
using System.IO.Ports;
using System.Threadings;
public class sample: MonoBehavior
{
SerialPort sp = new SerialPort("COM3", 9600)
public GameObject Image;
void Start()
{
sp.close();
sp.Open();
sp.ReadTimeout = 1;
}
void Update()
{
if(sp.IsOpen)
{
try
{
ArduinoString(sp.ReadLine());
print(ArduinoString);
}
catch(System.Exception)
{
}
}
void ArduinoString(string txt)
{
if(txt == "r")
{
Image.setActive(true);
}
Arduino Code
void setup()
{
Serial.begin(9600);
Serial.write("r");
Serial.flush();
}
void loop()
{
}