All enemies follow the player problem

Hi.

I have two enemy in the scene that each enemy have trigger zone like below picture.

alt text

now i want when the player enter to trigger zone, current enemy follow the player. problem is when player enter to one trigger zone,
all enemies follow the player. (I attached NavMeshAgent to all enemies).

this is my code:

this code is attached to all enemies and check for trigger zone.

AITrigger.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AITrigger : MonoBehaviour {

	[HideInInspector] public bool AIState;
    [HideInInspector] public GameObject[] enemyObj;


    void Awake()
    {
        enemyObj = GameObject.FindGameObjectsWithTag("Enemy");
    }


	void OnTriggerEnter(Collider col)
	{
		if (col.gameObject.tag == "Player")
		{
            AIState = true;
		}
	}
}

and this is EnemyController Script that attached to all enemies.

EnemyController.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class EnemyController : MonoBehaviour
{

	[HideInInspector] public NavMeshAgent _navmesh;
	[HideInInspector] public Animator anim;
	GameObject player;
	AITrigger EnemyAI;

	// Use this for initialization
	void Start () 
	{
        _navmesh = GetComponent<NavMeshAgent>();
        anim = GetComponent<Animator> ();
		player = GameObject.FindWithTag ("Player");
		EnemyAI = GameObject.Find ("AI Trigger").GetComponent<AITrigger>();
    }

	// Update is called once per frame
	void FixedUpdate ()
	{
        for (int i = 0; i < EnemyAI.enemyObj.Length; i++)
        {
			if (EnemyAI.AIState == true)
			{
				anim.SetBool("IsWalking", true);
				_navmesh.SetDestination(player.transform.position);
			}
			else if (target.IsTrigger == true)
			{
				transform.LookAt(player.transform);
				anim.SetBool("IsWalking", false);
			}
        }
	}
}

anyone know how can fix this problem?

Thanks.

place OnTriggerEnter function in EnemyController script .

Thanks.

I have another problem with All Enemies Follow player when gun hit collide to one enemy.

this is my gun code:

Gun.cs

 public class Gun : MonoBehaviour {
 
     RaycastHit hit;
     public Camera fpsCam;
     public float range = 100f;
     float Health = 100f
	 public LayerMask mask;
     
     void Update ()
     {    
         if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range, mask))
         {
			// Do something
         }
     }
 }

and this is my EnemyController code:

EnemyController.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class EnemyController : MonoBehaviour
{

	[HideInInspector] public NavMeshAgent _navmesh;
	[HideInInspector] public Animator anim;
	GameObject player;
    [HideInInspector] public bool AIState;
    [HideInInspector] public int MaxEnemy = 5;
    Gun gun;

    // Use this for initialization
    void Start () 
	{
        _navmesh = GetComponent<NavMeshAgent>();
        anim = GetComponent<Animator> ();
		player = GameObject.FindWithTag ("Player");
		gun = GameObject.Find ("AK47").GetComponent<Gun>();
    }

	// Update is called once per frame
	void FixedUpdate ()
	{
		float distance = Vector3.Distance (transform.position, player.transform.position);

        for (int i = 0; i <= MaxEnemy; i++)
        {
            if (this.GetComponent<Target>().health > 0)
            {
                if ((AIState == true && distance > 3f) || (gun.hit.transform != null && gun.hit.rigidbody != null && distance > 3f))
                {
                    anim.SetBool("IsWalking", true);
                    _navmesh.SetDestination(player.transform.position);
                    _navmesh.acceleration = 120f;
                }
                else if (distance <= 3f)
                {
                    transform.LookAt(player.transform);
                    anim.SetBool("IsWalking", false);
                    _navmesh.acceleration = 200f;
                }
            }
            else
            {
                _navmesh.speed = 0;
                //_navmesh.acceleration = 200f;
                anim.SetBool("IsWalking", false);
                anim.SetTrigger("Dead");
            }
        }
	}


    void OnTriggerEnter(Collider col)
    {
        if (col.gameObject.tag == "Player")
        {
            AIState = true;
        }
    }
}

problem is relate to this part (gun.hit.rigidbody != null):

if ((AIState == true && distance > 3f) || (gun.hit1.transform != null && gun.hit.rigidbody != null && distance > 3f))