List bestWay() {
List<GameObject> bestWay = new List<GameObject>();
GameObject[] wayPoints = GameObject.FindGameObjectsWithTag("wayPoint");
foreach(GameObject wp in wayPoints) {
bool colEnemyWp = Physics.Linecast(myTrans.position, wp.transform.position);
bool colWpTarget = Physics.Linecast(wp.transform.position, myTrans.position);
if((!colEnemyWp) && (!colWpTarget))
{
possibleWays.Add(wp);
}
}
if(possibleWays.Count > 1)
{
float minorTotalMovement = Mathf.Infinity;
foreach(GameObject wp in bestWay)
{
float curTotalMovement = Vector3.Distance(myTrans.position, wp.transform.position) +
Vector3.Distance(wp.transform.position, Player.transform.position);
if(curTotalMovement < minorTotalMovement)
{
minorTotalMovement = curTotalMovement;
} else
{
bestWay.Remove(wp);
}
}
}
bestWay = possibleWays;
return new List<GameObject>(bestWay);
}
I want to know why ‘possibleWays.Count’ returns me 0 out of the foreach and inside it returns me 4?
Thanks from now!
*Is it something wrong about asking a lot in here? Because I’m doing this ![]()
But, as always, some help would be appreciated! Thanks from now!