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

48 lines
1.0 KiB
C#
Raw Permalink Normal View History

2024-08-17 19:07:25 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
2024-08-18 20:01:15 +00:00
public class StationaryDefectDetector : MonoBehaviour, IResetable
2024-08-17 19:07:25 +00:00
{
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-18 20:01:15 +00:00
public void ResetMachine()
{
_knownProducts.Clear();
}
2024-08-18 15:48:35 +00:00
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
}
}
}
}