The list is updated depending on the proximity of my character. (from accepted answer)
Now what I want to do is assign the same name to every gameobject that come after the
first 4 gameobjects of my list, without having to do it manually everytime.
Think of something like this (list[4,5,6,7,…]).name = “wall_wait”;
import System.Collections.Generic;
function Update() {
var array = GameObject.FindGameObjectsWithTag("walls");
var list = List.<GameObject>(array);
list.Sort(ByDistance);
for (var gameObject in list)
(list[0]).name = "wall_1";
(list[1]).name = "wall_2";
(list[2]).name = "wall_3";
(list[3]).name = "wall_4";
//-------------------------------------------------
(list[4]).name = "wall_wait";
(list[5]).name = "wall_wait";
(list[6]).name = "wall_wait";
(list[7]).name = "wall_wait";
//...and so on
}
}
function ByDistance(a : GameObject, b : GameObject) : int{
var dstToA = Vector3.Distance(transform.position, a.transform.position);
var dstToB = Vector3.Distance(transform.position, b.transform.position);
return dstToA.CompareTo(dstToB);
}