1
0
mirror of synced 2024-12-13 06:51:07 +01:00
WACVR/Assets/Script/Serial/ColliderToSerial.cs
2022-10-03 02:04:54 +02:00

38 lines
994 B
C#

using UnityEngine;
using System.IO.Ports;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
public class ColliderToSerial : MonoBehaviour
{
public LightManager LightManager;
private int _insideColliderCount = 0;
public static event Action touchDidChange;
private int Area;
private void Start()
{
Area = Convert.ToInt32(gameObject.name);
}
private void OnTriggerEnter(Collider other)
{
_insideColliderCount += 1;
Serial.SetTouch(Area, true);
touchDidChange?.Invoke();
LightManager.UpdateLightFade(Area, true);
}
private void OnTriggerExit(Collider other)
{
_insideColliderCount -= 1;
_insideColliderCount = Mathf.Max(0, _insideColliderCount);
if (_insideColliderCount == 0)
{
Serial.SetTouch(Area, false);
touchDidChange?.Invoke();
LightManager.UpdateLightFade(Area, false);
}
}
}