void TargetNode(ref PathNode nodeA, PathType type) { int offSet = 0; if (nodeA.z % 2 == 0) { offSet = 6; } PathNode nodeB; for (int i = 0; i < 6; i++) { Vector3Int checkPos = Vector3Int.zero; checkPos.x = Mathf.Clamp(nodeA.x + checkOffSets[i + offSet].x, 0, gridX - 1); checkPos.z = Mathf.Clamp(nodeA.z + checkOffSets[i + offSet].z, 0, gridZ - 1); nodeB = pathGrids[type][checkPos.x, checkPos.z]; if (nodeB.cost != null && nodeB.cost < nodeA.cost) { RaycastHit hit; Vector3 rayPos = TerrainGen.GetHexPosition(nodeB.positionVec); rayPos.y += 1; Physics.Raycast(rayPos, Vector3.down, out hit, 5f); if (debug) { Debug.DrawRay(rayPos, Vector3.down, Color.blue, 0.5f); } if (hit.collider != null) { BuildingBase buildingBase = null; buildingBase = hit.collider.transform.parent.gameObject.GetComponent <BuildingBase>(); if (buildingBase != null && buildingBase.HasProperty(BuildingProperties.blocking)) { Debug.DrawRay(hit.collider.transform.parent.gameObject.transform.position, Vector3.up, Color.magenta, 8f); nodeB.cost = 100000; if (nodeA.target == nodeB.position) { i = 0; nodeA.target = Vector2Int.zero; nodeA.cost = 10000; } continue; } } float heightDif = TerrainGen.GetHexHeight(nodeA.positionVec) - TerrainGen.GetHexHeight(nodeB.positionVec); heightDif = heightDif / TerrainGen.hexSize / 2; if (type == PathType.flight) { heightDif = 0; } switch (Mathf.RoundToInt(heightDif)) { case 0: if (nodeB.cost + walkCost < nodeA.cost) { nodeA.target = nodeB.position; nodeA.cost = nodeB.cost + walkCost; } break; case 1: if (nodeB.cost + climbCost < nodeA.cost) { nodeA.target = nodeB.position; nodeA.cost = nodeB.cost + climbCost; } break; } } } }