public void UpdateUnitposition(BaseUnit unit, int tile) { BaseUnit oldUnit = _units[unit.GetGridPosition()]; if (oldUnit != unit || _units[tile] != null) { Debug.Log("something is wrong old and new are different"); } _units[unit.GetGridPosition()] = null; _units[tile] = unit; unit.SetGridPosition(tile); }
public void RemoveEnemy(BaseUnit unit) { Battleground.Instance.RemoveUnitFromBattleGround(unit.GetGridPosition()); _enemies.Remove(unit); if (_enemies.Count < 1) { Debug.Log("VICTORY!!!"); Debug.Break(); } }
void CheckMouseAgainstUnits() { Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); RaycastHit2D[] hits; hits = Physics2D.RaycastAll(mousePos, Vector2.zero, 0f, ~(1 << 5)); // inverse of UI layer if (hits.Length > 0) { GameObject closer = gameObject; // Just random assignement float minDist = 9999f; for (int i = 0; i < hits.Length; i++) { float dist = (hits[i].collider.transform.position - mousePos).sqrMagnitude; if (dist < minDist) { minDist = dist; closer = hits[i].collider.gameObject; } } BaseUnit unit = closer.transform.root.GetComponentInChildren <BaseUnit>(); if (unit) { int tile = unit.GetGridPosition(); if (tile >= 0) { SetTileHighlighted(tile); } else { ClearHighlights(); } } else { Debug.Log("closer= " + closer.name + " has no baseunit"); Debug.Log("hit= " + hits[0].transform.name); } } else { ClearHighlights(); } }