I am new to programming and I need help with optimization. Basically part of my method:
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) {
So, I'm looking for a tile in a position that is 1 unit above the current tile. My problem is that it takes 0.1 s for the whole method, which leads to a slight upward movement. Without Array.Find method is 0.01 s.
I also tried with the for loop, but still not a very good result, because I need 3 more checks for the bottom, left and right.
Can someone help me and show me a way to get quick results? Maybe I should go with something like slicing?
source share