// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Escape) && oldPath != null) { if (oldPath != null) { coloredPath(oldPath, Color.white); } startPosition = null; endPosition = null; oldStartPosition = null; oldEndPosition = null; oldPath = null; } if (startPosition != null && startPosition != oldStartPosition) { makeGraph(); findPathes = DijkstraAlgorithm.FindPathes(startPosition, otherGraph); oldStartPosition = startPosition; } if (endPosition != null && endPosition != oldEndPosition && startPosition != endPosition) { var path = findPathes.Find(e => e.Count > 0 && Equals(e[e.Count - 1], endPosition)); if (path != null) { if (oldPath != null) { coloredPath(oldPath, Color.white); for (int j = 0; j < oldEndPosition.transform.childCount; j++) { oldEndPosition.transform.GetChild(j).GetComponent <SpriteRenderer>().color = Color.white; } } fillOldPath(path); coloredPath(path, new Color(0, 255, 0, 0.5f)); oldEndPosition = endPosition; } } }