2024-08-17 19:07:25 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.Events;
|
|
|
|
|
|
|
|
public class StationaryDefectDetector : MonoBehaviour
|
|
|
|
{
|
2024-08-18 12:44:44 +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-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)
|
|
|
|
{
|
2024-08-18 12:44:44 +00:00
|
|
|
if (other.TryGetComponent(out Product product))
|
2024-08-17 19:07:25 +00:00
|
|
|
{
|
2024-08-18 12:44:44 +00:00
|
|
|
if (_knownProducts.Contains(product))
|
2024-08-17 19:07:25 +00:00
|
|
|
{
|
2024-08-18 12:44:44 +00:00
|
|
|
_knownProducts.Remove(product);
|
2024-08-17 19:07:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|