I am fairly new to programming and i need some help with optimizing. Basically a part of my method does:
for(int i = 0; i < Tiles.Length; i++)
{
x = Tiles[i].WorldPosition.x;
y = Tiles[i].WorldPosition.y;
z = Tiles[i].WorldPosition.z;
Tile topsearch = Array.Find(Tiles,
search => search.WorldPosition == Tiles[i].WorldPosition +
new Vector3Int(0,1,0));
if(topsearch.isEmpty)
{
// DoMyThing
}
}
So i am searching for a Tile in a position which is 1 unit above the current Tile.
My problem is that for the whole method it takes 0.1 secs which results in a small hick up..Without Array.Find
the method is 0.01 secs.
I tried with a for loop also, but still not great result, because i need 3 more checks for the bottom, left and right..
Can somebody help me out and point me a way of acquiring some fast results? Maybe i should go with something like threading?