From 05da9f6caaa7429614241b2e814d66798517f216 Mon Sep 17 00:00:00 2001 From: Kylemc1413 Date: Tue, 24 May 2022 20:48:15 -0400 Subject: [PATCH] Close Serial Ports in OnDestroy --- Assets/Script/Serial.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Assets/Script/Serial.cs b/Assets/Script/Serial.cs index 83ac0eb..f302af0 100644 --- a/Assets/Script/Serial.cs +++ b/Assets/Script/Serial.cs @@ -48,6 +48,11 @@ public class Serial : MonoBehaviour ColliderToSerial.touchDidChange += SendTouchState; } + private void OnDestroy() + { + ComL.Close(); + ComR.Close(); + } void Update() { if(ComL.IsOpen) @@ -62,11 +67,14 @@ public class Serial : MonoBehaviour private void SendTouchState() { - Debug.Log("Sending Touch State"); - Debug.Log("Sending Left"); - SendTouch(ComL, TouchPackL); - Debug.Log("Sending Right"); - SendTouch(ComR, TouchPackR); + if(StartUp) + { + Debug.Log("Sending Touch State"); + // Debug.Log("Sending Left"); + SendTouch(ComL, TouchPackL); + // Debug.Log("Sending Right"); + SendTouch(ComR, TouchPackR); + } } private void FixedUpdate() { //SendTouchState();