I have 2 Booleans which define;
- if the player is seen (A)
- if another NavmeshAgent is within a radius (B)
i would like that if the player is not seen but if a navmesh agent is within the radius, the agents go to one another. For some reason if i put both in the Update(), B will not read as true unless A is true and vice versa. Ideas?
public class PlayerController : MonoBehaviour
{
public NavMeshAgent agent;
public Transform player;
public float maxAngle;
public float maxRadius;
public float maxHear;
private bool isInFOV = false;
private bool isInAudio = false;
public static bool inFOV(Transform checkingObject, Transform target, float maxAngle, float maxRadius)
{
Collider[ ] overlaps = new Collider[10];
int count = Physics.OverlapSphereNonAlloc(checkingObject.position, maxRadius, overlaps);
for (int i = 0; i < count + 1; i++)
{
if (overlaps[1] != null)
{
if (overlaps*.transform == target)*
*{*
*UnityEngine.Vector3 directionBetween = (target.position - checkingObject.position).normalized;*
_directionBetween.y *= 0;_
*float angle = UnityEngine.Vector3.Angle(checkingObject.forward, directionBetween);*
*if (angle <= maxAngle)*
*{*
*Ray Sight = new Ray(checkingObject.position, target.position - checkingObject.position);*
*RaycastHit hit;*
*if (Physics.Raycast(Sight, out hit, maxRadius))*
*{*
*if (hit.transform == target)*
*{*
*return true;*
*}*
*}*
*}*
*}*
*}*
*}*
*return false;*
*}*
*public static bool inAudio(Transform checkingObject1, Transform target1, float maxHear)*
*{*
*Collider[ ] overlaps1 = new Collider[10];*
*int count1 = Physics.OverlapSphereNonAlloc(checkingObject1.position, maxHear, overlaps1);*
*for (int i = 0; i < count1 + 1; i++)*
*{*
*if (overlaps1[1] != null)*
*{*
_if (overlaps1*.transform == target1)*_
_*{*_
_*return true;*_
_*}*_
_*}*_
_*}*_
_*return false;*_
_*}*_
_*private void Start()*_
_*{*_
_*agent = GetComponent<NavMeshAgent>();*_
_*}*_
_*// Update is called once per frame*_
_*void Update()*_
_*{*_
_*GameObject[ ] gos;*_
_*gos = GameObject.FindGameObjectsWithTag("Zombie");*_
_*GameObject closest = null;*_
_*float distance = Mathf.Infinity;*_
_*foreach (GameObject go in gos)*_
_*{*_
_*UnityEngine.Vector3 diff = go.transform.position - agent.transform.position;*_
_*float curDistance = diff.sqrMagnitude;*_
_*if (curDistance < distance && curDistance > 0)*_
_*{*_
_*closest = go;*_
_*distance = curDistance;*_
_*}*_
_*}*_
_*isInFOV = inFOV(transform, player, maxAngle, maxRadius);*_
_*isInAudio = inAudio(transform, closest.transform, maxHear);*_
_*print(isInAudio);*_
_*if (isInFOV == true)*_
_*{*_
_*isInAudio = false;*_
_*agent.SetDestination(player.position);*_
_*isInFOV = false;*_
_*}*_
_*if (isInAudio == true)*_
_*{*_
_*agent.SetDestination(closest.transform.position);*_
_*isInAudio = false;*_
_*}*_
_*}*_
_*}*_
_*```*_