freindly ai attack other ai.

Hi i made a simple ai that shoot only the player. and i was wondering how to make a Ai that actually shoot other ai’s (like a huge ai battle). I’m using java, and i know we need to use an array. but i can’t see what to do for making the ai attack other ai’s. is there a On tags function maybe? i don’t really know. can someone help please.

it’s for building friendly ai’s to shoot the enemies ai’s instead targetting me. i want to make an ai like a sand box. i want to make a script that makes me juste to put multiple ai’s in a team and automatically shoot’s the other team. a bit like Arma editor where you just place infentries set there teams and see the action taking place. but the problem is that i remarque that there is actually no tutorial explaining that. i know that it’s array with loops but i don’t know a way to implement that.

here is a turret script for the ai :

//var player : GameObject[];
var player : GameObject;
 var safeDist : float = 15;
 var currentDist : float;
 var shooting : boolean = false;
 var bang : AudioClip;
 var bulletFab : Rigidbody;
 var gunTip : Transform;
 var power : float = 1000;
 var shotDelay : float = 1;


 function Start (){
  player = GameObject.FindGameObjectsWithTag("blueTeam");
 }
 
 
 function Update () {
    
         currentDist = Vector3.Distance(transform.position, player.position);
     
         if(currentDist < safeDist){
             transform.LookAt(transform.position, player.position);
             if(!shooting) shootStuff();
     
         
     }
         
 }
 
 function shootStuff(){
     
     shooting = true;
     
    
     //for ( var i = 0 ; i <player.Length; i++){
         AudioSource.PlayClipAtPoint(bang, transform.position);
     
         var fwd = transform.TransformDirection(Vector3.forward);
         var bulletShot : Rigidbody = Instantiate(bulletFab, gunTip.position, gunTip.rotation);
         bulletShot.AddForce(fwd * power);
     
         yield WaitForSeconds(shotDelay);
         shooting = false;
     
   //  }
 }

what i put in “//” is where i think to put. the problem is that i think that the script was meant for one target.

Say each team has 3 AIs : (A1, A2, A3) vs (B1, B2, B3).

Say after getting list of B team, A1 focus fire on B2, only when B2 die (no matter killed by who), A1 will search for other target until no target left. Is that what you want?

If so you should do something like this

var player : GameObject[];
var currentTarget : Transform;
var safeDist : float = 15;
var currentDist : float;
var shooting : boolean = false;
var bang : AudioClip;
var bulletFab : Rigidbody;
var gunTip : Transform;
var power : float = 1000;
var shotDelay : float = 1;
 
 
function Start (){
	
}
  
  
function Update () {
	//if target is alive/not null then shoot
    if(currentTarget)
	{
		currentDist = Vector3.Distance(transform.position, currentTarget.position);
      
		if(currentDist < safeDist){
			transform.LookAt(transform.position, currentTarget.position);
			if(!shooting) shootStuff();
		}
    }
	else //if not then search for new target
	{
		player = GameObject.FindGameObjectsWithTag("blueTeam");
		//pick random target
		if(player.Length > 0)
		{
			Random rand = new Random();
			var  n = rand.nextInt(player.Length);
			currentTarget = player[n];
		}
	}
}
  
function shootStuff(){
      
	shooting = true;
	AudioSource.PlayClipAtPoint(bang, transform.position);
      
	var fwd = transform.TransformDirection(Vector3.forward);
	var bulletShot : Rigidbody = Instantiate(bulletFab, gunTip.position, gunTip.rotation);
	bulletShot.AddForce(fwd * power);
      
	yield WaitForSeconds(shotDelay);
	shooting = false;
}