using System.Collections.Generic;
using System.Collections;
using UnityEngine;
public class Hearing : MonoBehaviour
{
[SerializeField]
private Transform target;
[SerializeField]
private float radius;
public float hearing;
public bool playerdetected;
void Start()
{
hearing = 10f;
}
void Update()
{
Collider[] targetsinRadius = Physics.OverlapSphere(transform.position, 50f);
foreach (Collider targetCollider in targetsinRadius)
{
if(targetCollider.tag == "enemy")
{
target = targetCollider.transform;
EnemyStats enemystat = GetComponent<EnemyStats>();
if (enemystat != null)
{
if (enemystat.noise >= hearing)
{
playerdetected = true;
}
}
}
}
}
I’m triyng to compare the noise level of the detected object with my hearing to switch on a bool but it’s not working. A point in the right direction would be greatly appreciated.
}