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;
        }
    }
Beispiel #2
0
	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");
			}
				
		}
	}
Beispiel #3
0
 protected virtual void Awake()
 {
     inRange         = false;
     isUIinitialized = false;
     currentNode     = grid.FindNode(transform.position);
     StartCoroutine(InitRangeNodes());
 }
Beispiel #4
0
    private IEnumerator Start()
    {
        yield return(null);

        currentNode            = grid.FindNode(transform.position);
        currentNode.isOccupied = true;
    }