private void moveUnits(GameObject target, Troop troop) { if (troop.hasMovableUnits()) { foreach (var unit in troop.units) { Construct scriptConstruct = unit.GetComponent<Construct>(); if (scriptConstruct != null) { if (scriptConstruct.getConstruct() || scriptConstruct.getInConstruction()) { scriptConstruct.setConstruct(false); scriptConstruct.SetInConstruction(false); scriptConstruct.getBuildingToConstruct().GetComponentOrEnd<BuildingConstruction>().deleteUnit(unit); } } UnitMovement script = unit.GetComponentInParent<UnitMovement>(); if (script != null) { script.startMoving(target); target.GetComponent<timerDeath>().AddUnit(unit); } } } else { foreach (var unit in troop.units) { Spawner script = unit.GetComponentInParent<Spawner>(); if (script != null) { script.RallyPoint = target.transform.position; } } Destroy(target.gameObject); } }