private bool ExistsObstacle(NodeBehaviour targetNode) { Vector3 direction = targetNode.transform.position - transform.position; if (Physics.Raycast(transform.position, direction, BoardBehaviour.SPACING, obstacleLayer)) { return(true); } return(false); }
public void FindNeighbors(NodeBehaviour[] nodes) { for (int i = 0; i < BoardBehaviour.directions.Length; i++) { NodeBehaviour neighbor = Array.Find(nodes, n => n.transform.localPosition == transform.localPosition + BoardBehaviour.directions[i]); if (neighbor != null) { if (!ExistsObstacle(neighbor)) { nodeNeighbor.Add(neighbor); } } } }
private void LinkToNode(NodeBehaviour targetNode) { if (linkPrefab != null) { GameObject newLink = Instantiate(linkPrefab, transform); newLink.GetComponent <LinkBehaviour>().DrawLink(transform.position, targetNode.transform.position); if (!linkedNodes.Contains(targetNode)) { linkedNodes.Add(targetNode); } if (!targetNode.linkedNodes.Contains(this)) { targetNode.linkedNodes.Add(this); } } }