2022-01-05 19:44:30 +01:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class TouchToSerial : MonoBehaviour
|
|
|
|
{
|
|
|
|
public int Area;
|
2022-03-15 18:51:21 +01:00
|
|
|
private int _insideColliderCount = 0;
|
2022-01-05 20:38:10 +01:00
|
|
|
private void OnTriggerEnter(Collider other)
|
2022-01-05 19:44:30 +01:00
|
|
|
{
|
2022-03-15 18:51:21 +01:00
|
|
|
Serial.ChangeTouch((int)Area, true);
|
|
|
|
Serial.SendTouch();
|
2022-03-15 17:15:34 +01:00
|
|
|
_insideColliderCount += 1;
|
2022-01-05 19:44:30 +01:00
|
|
|
}
|
|
|
|
|
2022-01-05 20:38:10 +01:00
|
|
|
private void OnTriggerExit(Collider other)
|
2022-01-05 19:44:30 +01:00
|
|
|
{
|
2022-03-15 18:51:21 +01:00
|
|
|
if (_insideColliderCount == 0)
|
|
|
|
{
|
|
|
|
Serial.ChangeTouch((int)Area, false);
|
|
|
|
Serial.SendTouch();
|
|
|
|
}
|
2022-03-15 17:15:34 +01:00
|
|
|
_insideColliderCount -= 1;
|
|
|
|
_insideColliderCount = Mathf.Max(0, _insideColliderCount);
|
2022-01-05 19:44:30 +01:00
|
|
|
}
|
|
|
|
}
|