Hello,
I'm working on a pathfinder of type A*, but I'm having some trouble trying to iterate each move.
Here's the code I've got so far:
while (tilesForSearching.length > 0) //While there is tiles to be searched...
{
for(var tile : GameObject in tilesForSearching) //...do this to each one...
{
var refTile = tile.GetComponent.(); //Reference for convenience.
refTile.state = 2; //...state of the tile is set to 2 (searching)...
tile.GetComponent.().color = Color.yellow; //Turns it yellow when it has been walked over.
//...all adjacent tiles is added to tilesForSearching...
if(refTile.adjacentTile_upper && refTile.adjacentTile_upper.GetComponent.().state == 0)
{
tilesForSearching.Add(refTile.adjacentTile_upper);
}
if(refTile.adjacentTile_lower && refTile.adjacentTile_lower.GetComponent.().state == 0)
{
tilesForSearching.Add(refTile.adjacentTile_lower);
}
if(refTile.adjacentTile_right && refTile.adjacentTile_right.GetComponent.().state == 0)
{
tilesForSearching.Add(refTile.adjacentTile_right);
}
if(refTile.adjacentTile_left && refTile.adjacentTile_left.GetComponent.().state == 0)
{
tilesForSearching.Add(refTile.adjacentTile_left);
}
//...removes itself from tilesForSearching...
tilesForSearching.Shift();
}
}
It checks if the variable state is equal to 0, which means that it is open and walkable.
At the moment, every tile is set to 0/open.
So in theory every tile should become yellow, this is not the case.
![alt text][1]
[1]: /storage/temp/49453-skjermbilde-2015-07-04-kl-002818.png
*For some reason the upper right tiles are not yellow.*
I think the fault may be when it's trying to remove the tile from the array, but in all honesty - I have no idea why it's not working.
↧