- Home /
have friendly AI look at enemy
using UnityEngine; using System; using UnityEngine.AI;
public class Sense : MonoBehaviour {
public float checkRadius;
public LayerMask checkLayers;
public NavMeshAgent myNavMesh;
private GameObject[] closestZombie;
void Update ()
{
Collider[] colliders = Physics.OverlapSphere(transform.position, checkRadius, checkLayers);
//Array.Sort(colliders, new DistanceComparer(transform));
myNavMesh.transform.LookAt(Collider.gameObject);
foreach (Collider item in colliders)
{
Debug.Log(item.name);
}
//transform.LookAt(collider.gameObject);
}
private void OnDrawGizmos()
{
Gizmos.DrawWireSphere(transform.position, checkRadius);
}
}
I am trying to get my freindly ai to look at the nearest enemy, it can detect it, but i can not get it to look that way, I have all the enemies in their own layer
Comment