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);
}
}
}