Generic list of objects, then distance to those objects? (js)

Hi, I’m working on my own pathfinding solution, for learning purposes, and the only tutorial I understood (mainly because it was in javascript not C#) was Eteetski’s AI pathfinding, but It gives me an error even tho I copied it to the letter.

Anyway, ofc I ran into a problem as soon as I started. xD
I read that arrays are slow and don’t have type casting, builtin arrays, which I always used for everything so far are the fastest, but can’t be resized or added to, so I ended up with generic lists being the answer as faster than arrays.

Now I’ve never ever worked with lists before so I’m not quite sure how to handle them especially in for loops.

What I want to do is get a list of all gameObjects or transforms (not sure yet), on trigger enter. And that part I managed.
But now I want to get the distance of all those objects to another object, the enemy, and put it in another list, but the way I have it set up now it only returns 2 values when there should be 4 since there’s 4 in the initial list.

Here’s the code I have so far:

#pragma strict
import System.Collections.Generic;

var doors : List.<Transform>;
var doorToEnemyDistance : List.<float>;

function OnTriggerEnter(trig : Collider)
	if(trig.gameObject.tag == "AIPathDoor")
	if(trig.gameObject.tag == "Enemy")
		for (var i = 0; i < doors.Count; i++)
			var distance = Vector3.Distance(trig.gameObject.transform.position, doors*.position);*
  •  	doorToEnemyDistance.Add(distance);*
  •  }*
  • }*

Without seeing your scene, its really hard to figure it out. try adding Debug.Log(doors.count); to your if(trig.gameObject.tag == “Enemy”) block. Perhaps your loop is only running twice, in which case the problem is somewhere else (perhaps the other if statement?). your code seems fine…