Added defect detector prefab.

This commit is contained in:
Khauvinkh
2024-08-17 21:07:25 +02:00
parent ece1afe008
commit ae76789a51
7 changed files with 534 additions and 2 deletions

View File

@@ -0,0 +1,13 @@
using UnityEngine;
public class AudioAlarm : MonoBehaviour
{
public float Duration;
private bool _isPlaying;
public void PlayAlarm()
{
Debug.Log("Playing alarm");
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c996d1be4ecb4e8d92bc4344f7f98854
timeCreated: 1723921340

View File

@@ -0,0 +1,59 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class StationaryDefectDetector : MonoBehaviour
{
public UnityEvent AlarmEvent;
[Range(0, 100)]
public int FalsePositiveChance;
[Range(0, 100)]
public int FalseNegativeChance;
public List<Product> _detectedDefects;
private void OnTriggerEnter(Collider other)
{
if (other.TryGetComponent(out Product product))
{
if (_detectedDefects.Contains(product))
{
return;
}
_detectedDefects.Add(product);
if (other.TryGetComponent(out DefectiveProduct defectiveProduct))
{
var falseNegativeRoll = Random.Range(0, 100);
if (falseNegativeRoll > FalseNegativeChance)
{
AlarmEvent.Invoke();
}
}
else
{
var falsePositiveRoll = Random.Range(0, 100);
if (falsePositiveRoll < FalsePositiveChance)
{
AlarmEvent.Invoke();
}
}
}
}
private void OnTriggerExit(Collider other)
{
if (other.TryGetComponent(out DefectiveProduct product))
{
if (_detectedDefects.Contains(product))
{
_detectedDefects.Remove(product);
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e00ad13b6427460abe6c3aec6566b6e5
timeCreated: 1723920624

View File

@@ -17,14 +17,14 @@ public class ProductDescription : ScriptableObject
public GameObject GetRandomProduct()
{
float randomValue = Random.value;
float randomValue = Random.Range(0, 100);
float sum = 0;
for (var i = 0; i < Products.Length; i++)
{
var product = Products[i];
sum += product.Probability / 100f;
sum += product.Probability;
if (randomValue <= sum)
{
return product.Prefab;