Helicopter attack each hood?

Hey guys Rio here, I’m still in the build of The Drop City, and i have this helicopter script where i need it to attack the closest target on the map when approaching after being triggered…

Its identifying each hood already but i can’t seem to get it to identify each hood then select the closest one then engage it… and after its done with that target go to the next one…any help anyone?

var targets : GameObject[];
var ClosestTarget : Transform;
var rotationSpeed = 5; 
var myTransform : Transform; 
var canMove : boolean = true;
var inCombat : boolean = false;
var missleLaunch : Transform;
var AttckactiveHoods : int = 0;
var HoodHealthScript : HoodHealth;
var _distanceFromEnemy : float = 0;


function Awake(){
	HoodCheck1();
	myTransform = transform; 
	HoodHealthScript = GameObject.FindObjectOfType(typeof(HoodHealth)) as HoodHealth;
	targets = GameObject.FindObjectOfType(typeof(Hood)) as GameObject[];
}



function Start(){
	//target = AttckactiveHoods.transform; 	
}



function Update () {
	var moveSpeed = Random.Range(30,80);

  //check to make sure not being attack. if attacked then inCombat = true. applies to both enemy players and other minions.


  //if no enemy no longer in distance continue towards tower. inCombat == false

 
 //head to the next enemy if no enemy is in range or been attacked
   

    if(canMove == true  inCombat == false  HoodHealthScript.tower1destroyed == false) {
   		 myTransform.rotation = Quaternion.Slerp(myTransform.rotation,Quaternion.LookRotation(ClosestTarget.position - myTransform.position), rotationSpeed*Time.deltaTime); 
   		 myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;   
 }

 
 //if incombat == true then target / attack nearest enemy

}
//trigger while stay. Attack tower. If enemies come close then attack enemies instead so switch to inCombat
//towers not dead then keep attacking tower
function HoodCheck1() {
		var hoods : Hood[] = FindObjectsOfType(Hood) as Hood[];
		for (var hood : Hood in hoods) {
			AttckactiveHoods++;
		}
		_distanceFromEnemy = Vector3.Distance(transform.position, ClosestTarget.position);
	
	
		if(_distanceFromEnemy <= 2.0){
			
			
		}
		else
		if(_distanceFromEnemy <= 4.0){
			transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(ClosestTarget.position - transform.position), Time.deltaTime * 4);
			transform.Translate(0, 0, .11f);
		
		}else{
			//transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(_Player.position - transform.position), Time.deltaTime * 4);
			transform.Translate(0, 0, .1f);
	
			
		}
   }	
function OnTriggerEnter (col : Collider) {
	if(col.gameObject.tag == "HeliTrig"){
		Debug.Log("entered City");
	if(HoodHealthScript.tower1destroyed == false) {
		canMove = false;
		Instantiate(missleLaunch,this.transform.position,Quaternion.identity);
			}
		}
}

Bump

public Transform FindClosestTransformToPoint(GameObject[] hoods, Vector3 point) {
		float distance = Mathf.Infinity;
		Transform result = null;
		for(int i = 0; i < hoods.Length; ++i) {
			if(!hoods[i].enabled) continue;
			float thisDist = Vector3.Distance(point, hoods[i].transform.position);
			if(thisDist < distance) {
				distance = thisDist;
				result = hoods[i];
				Gizmos.DrawLine(point, hoods[i].transform.position);//See the closest point in editor
			}
		}
		return result;
	}

Thanks alot for responding, how can i write it in java, the public transform … I have been tryin for the last hr …

Bump

Please don’t bump your thread. If you are not getting the help you need it’s because your question is not clear. Rather than being lazy and say “bump”, or not-quite-so-lazy and say “I have been tryin for the last hr” why not post the JS code you have tried, and have problems with.

Didn’t know that, appologies