private void ShowMoveRange(bool show, UnitAndOrder unit) { if (unit.orders == null) { return; } GraphGrid grid = unit.orders.Grid; List <Node> nodesInRange = grid.GetAllNodesInRange(grid.FindNode(unit.GO.transform.position), unit.GO.GetComponent <Stats>().moveRange); foreach (Node node in nodesInRange) { if (show) { node.gameObject.GetComponent <MeshRenderer>().material = nodeInRangeMaterial; } else { node.gameObject.GetComponent <MeshRenderer>().material = normalNodeMaterial; } } if (show) { Node activeUnitNode = grid.FindNode(unit.GO.transform.position); activeUnitNode.gameObject.GetComponent <MeshRenderer>().material = activeUnitNodeMaterial; } }
public void MakePath(Vector3 target) { Node currentNode = Grid.FindNode(transform.position); Node startNode = currentNode; Node targetNode = Grid.FindNode(target); if (currentNode != null && targetNode != null) { List <Node> path = AstarPathfinding.Instance.FindPath(startNode, targetNode); if(path == null) { Debug.Log("astar nie dziala: (" + currentNode.normalCoordinates.x +","+ currentNode.normalCoordinates.y +") ("+ targetNode.normalCoordinates.x +"," + targetNode.normalCoordinates.y +")"); return; } if (path.Count <= gameObject.GetComponent<Stats>().moveRange) { Path = path; } else { Debug.Log("This tile is too far away"); } } }
protected virtual void Awake() { inRange = false; isUIinitialized = false; currentNode = grid.FindNode(transform.position); StartCoroutine(InitRangeNodes()); }
private IEnumerator Start() { yield return(null); currentNode = grid.FindNode(transform.position); currentNode.isOccupied = true; }