Hi there thanks for looking. The problem i am having is i need to be able to seleect the three closest spawn points held within my array. I need to pass in the closest and remove the furthest away but only allow 3 to be possible spawn points.
/*
Here there will be the functions that will deal with every aspect of the games enemy spawn system
There will be functions that are not required but i am testing as much as possible for performance
So when the game gets closer to be playebale we will remove the uneeded functions for performance wise
*/
var spawnPoint : Transform[];
var basicFodder : GameObject[];
var currentEnemies : int = 0;
var maxEnemies : int = 12;
var minEnemies : int = 8;
var spawn = true;
var bBasicFodder : boolean = true;
var spawnWait : float;
var spawnTriggers : Transform[];
var currentSpawn;
var minDistance : float;
var points;
function Update()
{
for(i=0; i<spawnPoint.Length; i++)// Checks the dist between all spawns and player
{
var distance = Vector3.Distance(transform.position, spawnPoint*.transform.position);// dustance for all elements in the array*
-
if(distance < minDistance)* -
{* -
print("It Works");// Tell us it work* -
minDistance = distance;* -
currentSpawn = i;* -
BasicFodder();* -
}* -
}*
}
*/// our basic fodder complete with spawning \*
function BasicFodder()
{
- while (bBasicFodder) // While bBasicFodder is true run the statement*
- {*
-
//if(bBasicFodder == true) // if our basic fodder is true start creating enemies.* -
//{* -
if (currentEnemies < minEnemies)* -
spawn = true; // if minEnemies reached start spawning* -
if (currentEnemies >= maxEnemies)* -
spawn = false; // if maxEnemies reached stop spawning* -
if (spawn)* -
{ // if spawning enabled create new enemy* -
// Randomize the different enemies to instantiate.* -
var m_Object : GameObject = basicFodder[Random.Range(0, basicFodder.length)];* -
// Randomize the spawnPoints to instantiate enemy at next.* -
var m_Position : Transform = spawnPoint[currentSpawn.length];* -
Instantiate(m_Object, m_Position.position, m_Position.rotation);* -
currentEnemies +=1;* -
}* -
//}*
yield WaitForSeconds(spawnWait); // free Unity for 2 seconds each loop anyway
- }*
}
Now the for loop only iterates the length of my array i need it to constantly go through and pick the closest 3 points on which to spawn from. Note this is not a zombie game!
So in short i need help picking the 3 closest points to me then pass those values into the BasicFodder Function so that it will only spawn from the 3 points that have been chosen and closest to me. Thanks For Looking And i hope you can help me.