enemy AI alerted script (help)

I’m not sure if this is the best method, but I don’t really know how to properly implement this function. I have an enemy with two sphere colliders. One is on the parent and the other is on the child. The parent sphere is responsible for the line-of-sight, if the player enter’s his line of sight, then he will attack and chase the player. The child sphere is responsible for alerting other enemies if their child sphere’s are colliding. So here’ part of my code to do it:

//script for parent 
public void OnTriggerStay(Collider playerEntered)
	{
		isAlerted = false;
		
		float distance = Vector3.Distance(player.transform.position, transform.position);
		
		//player enters enemy's line of sight
		if(playerEntered.gameObject.tag == "Player")
		{
			isAlerted = true;
			
			//attack the player
			if(isAlerted == true)
			{
				if(distance > attackDistance)
				{
					Quaternion rotation = Quaternion.LookRotation(player.position - transform.position);
					transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
					transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
					renderer.material.color = Color.red;
				}
			}
		}
		
		else
		{
			isAlerted = false;
		}
	}
//script for child sphere collider

	public void OnTriggerStay(Collider enemyAlert)
	{
		//if player is in sight, alert nearby zombie
		if(enemyAIScript.isAlerted == true  enemyAlert.gameObject.tag == "Enemy")
		{
                      //attack enemy
                       //what to put here?
		}
	}

You are overcomplicating it by adding a second sphere. If you place all of your enemies in an array, you can simply activate them by code. Just check their distance from the activated enemy and activate if they are within range.

Also, use OnTriggerEnter, not stay.

I’ve redone the code and tried using an overlapsphere instead. But I’m having an issue with the radius check. When my player is spotted the radius, despite being only 3 seems to alert other enemies no matter where they are. Here’s the code:

	void alertOthers()
	{
		Vector3 aiPosition = transform.position;
		float radius = 3;
		
		if(isAlterted == true)
		{
			Collider[] hitColliders = Physics.OverlapSphere(aiPosition, radius);
			
			foreach(Collider hit in hitColliders)
			{
				if(hit  hit.tag == "Enemy")
				{
					print("Enemy is Alerted");
				}
				
				else
				{
					isAlterted = false;
				}
			}
		}
	}

Is isAlerted set as a static var?

I figured out the problem. Its because he’s alerting himself. Not quiet sure how to prevent it from alerting itself though without removing the enemy tag.