So I am trying to create a path finding code for a turn-based game in a grid environment, I rewrote my code a lot of times in different ways, but it always ends freezing Unity, and I can’t find out whats wrong.
private void Move (GameObject t, GameObject c)
{
Debug.Log("Cheking at " + c.name);
if (t.gameObject.GetComponent<TileProps> ().walkable && !t.GetComponent<TileProps>().occupied) {
Collider[] nT = Physics.OverlapSphere(c.transform.position, tileSize);
List<GameObject> neighbors = new List<GameObject>();
foreach(Collider z in nT){
neighbors.Add(z.gameObject);
}
for(int i = 0; i < neighbors.Count; i++){
Debug.Log(neighbors*.name);*
if(!neighbors.GetComponent().walkable || neighbors_.GetComponent().occupied || checkedTiles.Contains(neighbors*)){*_
_ neighbors.Remove(neighbors*);*_
* }*
* }*
* if(neighbors.Count > 0){*
* for(int i = 0; i < neighbors.Count; i++){*
_ checkedTiles.Add(neighbors*);
tempList.Add(neighbors);*_
_ if(neighbors != t){_
* Debug.Log(“Looping…”);*
_ Move(t, neighbors*);*_
* }else{*
* if(tempList.Count < numOfTiles){*
* tilesToMove = tempList;*
* numOfTiles = tempList.Count;*
* tempList.RemoveRange(0, tempList.Count);*
* }*
* if(checkedTiles.Count == mapM.GetComponent().tiles.Count){*
* checkedTiles.RemoveRange(0, checkedTiles.Count);*
* Debug.Log(“Path Calculated”);*
* if(numOfTiles <= actionP){*
* StartCoroutine(Move2());*
* }else{*
* Debug.Log(“Not enough action points.”);*
* }*
* }*
* }*
* }*
* }else{*
* Debug.Log(“Target is not walkable”);*
* return;*
* }*
* }*
* }*