void initGrid() { Debug.Log("Initializing grid for combat..."); for (int y = 0; y <= 4; y++) { for (int x = 0; x < 10; x++) { CombatCell combatCellData = GetCellAt(x, y); combatCellData.dataUnit = new CombatDataUnit(); } } }
public void NearestCellToPlayer(Vector2 _pos, int raggio, GameObject playerNear) { if (playerNear.GetComponent <Player>() != null) { Player player = playerNear.GetComponent <Player>(); CombatCell nearestCell = null; int nearestCellDistance = 10000; int _x = (int)_pos.x; int _y = (int)_pos.y; // incomincia a scansionare l'area for (int i = (_x - raggio); i <= (_x + raggio); i++) { for (int y = (_y - raggio); y <= (_y + raggio); y++) { if (i < 0) { continue; } if (y < 0) { continue; } if (i > base.grid.width - 1) { continue; } if (y > base.grid.height - 1) { continue; } int distance = Mathf.Abs(i - (int)player.pos.x) + Mathf.Abs(y - (int)player.pos.y); if (distance <= nearestCellDistance && !base.grid.cells[i, y].isOccupied && Mathf.Abs(i - _x) + Mathf.Abs(y - _y) < raggio) { nearestCellDistance = distance; nearestCell = base.grid.cells[i, y]; } } } if (nearestCell != null) { StartCoroutine(GoToEndCell(_pos, nearestCell.pos)); } } else { FindNearestPlayer(); } }
void createGrid() { Debug.Log("Creating grid objects..."); for (int y = 0; y <= 4; y++) { for (int x = 0; x < 10; x++) { GameObject newCombatCell = Instantiate(combatCellPrefab, combatGridGameObject.transform); CombatCell combatCellData = newCombatCell.GetComponent <CombatCell>(); combatCellData.dataUnit = new CombatDataUnit(); combatCellData.locX = x; combatCellData.locY = y; combatGridUI.Add(combatCellData); } } }