Hello, i am making a 3D Tower Defense Game and I’m currently stuck on the targeting system, Specifically First and Last Targeting. Closest, strongest and weakest works fine. I belive i am on the good track when it comes to its logic but i dont know how to resize array based on value. Let me explain the system first. Every enemy has crossed times (ammount of times it has turned a corner) and distance to that corner it has to turn which is defined as a point. First targeting works by checking which enemy has the largest ammount of crossed times and lowest ammount of distance to the point its heading towards. Now i dont know how to make the array only count enemies with the largest ammount of crosses and not all of them. Any help is appreciated and here is my code for First targeting
List targets2 = new List();
Collider colliders2 = Physics.OverlapSphere(transform.position, Range, layers);
collidersCheck = colliders2;
for (int i = 0; i < colliders2.Length; i++)
{
valuesINT = new int[colliders2.Length];
for (int i2 = 0; i2 < colliders2.Length; i2++)
{
valuesINT[i2] = colliders2[i2].GetComponent<Enemy>().CrossedTimes;
}
SingleValueINT = Mathf.Max(valuesINT);
if (colliders2*.GetComponent<Enemy>().CrossedTimes == SingleValueINT)*
-
{*
-
valuesFLOAT = new float[colliders2.Length];*
-
for (int i2 = 0; i2 < colliders2.Length; i2++)*
-
{*
-
valuesFLOAT[i2] = colliders2[i2].GetComponent<Enemy>().DistanceToExit;*
-
}*
-
SingleValueFLOAT = Mathf.Min(valuesFLOAT);*
_ if (colliders2*.GetComponent().DistanceToExit == SingleValueFLOAT)_
_ {_
_ FirstEnemy = colliders2.GetComponent();
tower.Target = FirstEnemy;
}
}
}
if(colliders2.Length == 0)
{
tower.Target = null;
}*_