It’s basically a Path-finder. Added the walls and I improved a bit the script just to don't go trough walls and don't step back. É basicamente um Path-finder. Coloquei as paredes e dei uma melhorada no script para não atravessar a parede e não voltar atrás.
It checks which one of the directions is nearest to the target: Up, Down, Left or Right. Then it moves in the respective direction. Ele verifica qual das direções é mais perto do alvo: Cima, Baixo, Esquerda ou Direita. Assim, ele move para a tal direção. Thanks to the YouTube channel called “Game Mechanics Explained”, that also explained that. Obrigado para o canal do YouTube (traduzido) “Mecânicas de Jogos Explicadas”, que também explicou isto.