I recently posted a question with 2 problems in it…one problem was solved (thank you ‘sparkzbarca’), so now i have to deal with the other.
I have a bad guy with a sphere collider (set to isTrigger) which is quite large and detects when a civilian NPC passes into it. At this point, i’m trying to add that civilian to an array when it enters the sphere-trigger.
With my current code, when i print the length of the array, it only shows ‘1’, now matter how many civilians enter. What am i doing wrong?
var target : GameObject;
var newCiv;
function OnTriggerEnter (targets : Collider) {
if (targets.tag == "civilian"){
print ("civilian In Range");
newCiv = targets.gameObject;
print(newCiv);
}
}
function Update () {
civPos = newCiv.gameObject.transform.position;
var civTargets = new Array();
civTargets.Add(civPos);
print(civTargets.length);
}
I’m sure the answer is staring me in the face, but i just can’t see it. All help is always appreciated.
Tom ![]()