// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(1)) { if (gridList != null) { for (int i = 0; i < gridList.Count; i++) { Grid grid = gridList[i]; if (grid.currentType == GridType.Ground) { Debug.Log(i); grid.gameObject.GetComponent <MeshRenderer>().material.color = Color.white; } else if (grid.currentType == GridType.Forest) { grid.gameObject.GetComponent <MeshRenderer>().material.color = Color.green; } } } gridList = astar.GetShortestPath(start, end); for (int i = 0; i < gridList.Count; i++) { gridList[i].gameObject.GetComponent <MeshRenderer>().material.color = Color.red; } } }