1
0
mirror of synced 2024-12-03 18:27:16 +01:00
WACVR/Assets/Script/Serial/ColliderToSerial.cs

40 lines
1.1 KiB
C#
Raw Normal View History

2022-05-16 23:38:40 +02:00
using UnityEngine;
using System.IO.Ports;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
public class ColliderToSerial : MonoBehaviour
{
public GameObject LightManager;
private LightManager lightManager;
2022-05-16 23:38:40 +02:00
private int _insideColliderCount = 0;
public static event Action touchDidChange;
private int Area;
private void Start()
{
Area = Convert.ToInt32(gameObject.name);
lightManager = LightManager.GetComponent<LightManager>();
}
2022-05-16 23:38:40 +02:00
private void OnTriggerEnter(Collider other)
{
_insideColliderCount += 1;
Serial.SetTouch(Area, true);
touchDidChange?.Invoke();
2022-07-29 18:49:56 +02:00
lightManager.UpdateLightFade(Area, true);
2022-05-16 23:38:40 +02:00
}
private void OnTriggerExit(Collider other)
{
_insideColliderCount -= 1;
_insideColliderCount = Mathf.Max(0, _insideColliderCount);
if (_insideColliderCount == 0)
{
Serial.SetTouch(Area, false);
touchDidChange?.Invoke();
2022-07-29 18:49:56 +02:00
lightManager.UpdateLightFade(Area, false);
2022-05-16 23:38:40 +02:00
}
}
}