I’ve a list of gameobjects and I need to get a distance between gameobjects through RaycastHit. Is there a way to get unique distance for each gameobject looking to each other?
just use Vector3.Distance.
go with For thro each gameObject with thet list you have.
You gona do it like this:
var MyList : ArrayList; // This is your list of GameObjects.
var MyDistanceList : ArrayList; //This is empty list for storeing our distances.
function GetDistance()
{
for (var obj : GameObject in MyList)
{
MyDistanceList.Add(Vector3.Distance(transform.position, obj.transform.position)); //Add vaule to MyDistanceList on same index position as our target object in MyList.
}
}
So here you go a script thet creates list of distances of all gameObjects on your list with curnet one thet this script is attached to. Dont forget to use this function in Update or Start.