quality-control/Assets/Scripts/Machines/StationaryDefectDetector.cs

43 lines
961 B
C#
Raw Normal View History

2024-08-17 19:07:25 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class StationaryDefectDetector : MonoBehaviour
{
public List<Product> _knownProducts;
2024-08-17 19:07:25 +00:00
2024-08-18 15:48:35 +00:00
public AudioClip goodSound;
public AudioClip badSound;
2024-08-17 19:07:25 +00:00
private void OnTriggerEnter(Collider other)
{
2024-08-18 15:48:35 +00:00
var product = other.GetComponentInParent<Product>();
if (product == null)
2024-08-17 19:07:25 +00:00
{
2024-08-18 15:48:35 +00:00
return;
}
if (_knownProducts.Contains(product))
{
return;
}
2024-08-17 19:07:25 +00:00
2024-08-18 15:48:35 +00:00
_knownProducts.Add(product);
2024-08-17 19:07:25 +00:00
2024-08-18 15:48:35 +00:00
NAudio.Play(product.Defect == DefectType.None ? goodSound : badSound, transform.position);
2024-08-17 19:07:25 +00:00
}
private void OnTriggerExit(Collider other)
{
if (other.TryGetComponent(out Product product))
2024-08-17 19:07:25 +00:00
{
if (_knownProducts.Contains(product))
2024-08-17 19:07:25 +00:00
{
_knownProducts.Remove(product);
2024-08-17 19:07:25 +00:00
}
}
}
}