1
0
mirror of synced 2024-12-14 07:12:54 +01:00
WACVR/Assets/Script/ColliderToSerial.cs

40 lines
1016 B
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
{
private Renderer cr;
2022-05-16 23:38:40 +02:00
private int _insideColliderCount = 0;
public static event Action touchDidChange;
2022-05-16 23:38:40 +02:00
private void Start()
{
cr = GetComponent<Renderer>();
}
2022-05-16 23:38:40 +02:00
private void OnTriggerEnter(Collider other)
{
_insideColliderCount += 1;
Serial.SetTouch(Convert.ToInt32(gameObject.name), true);
touchDidChange?.Invoke();
cr.material.color = new Color(1f, 1f, 1f, 1f);
2022-05-16 23:38:40 +02:00
}
private void OnTriggerExit(Collider other)
{
_insideColliderCount -= 1;
_insideColliderCount = Mathf.Max(0, _insideColliderCount);
2022-05-16 23:38:40 +02:00
if (_insideColliderCount == 0)
{
Serial.SetTouch(Convert.ToInt32(gameObject.name), false);
touchDidChange?.Invoke();
cr.material.color = new Color(0f, 0f, 0f, 0f);
2022-05-16 23:38:40 +02:00
}
}
}