public void Update(IReadOnlyList <CommandUnit> units, int commanderIndex) { var updatedCommander = units[commanderIndex]; if (!Commander || updatedCommander != Commander) { NewCommander = true; CommanderIndex = commanderIndex; Commander = units[commanderIndex]; var center = Vector3.zero; foreach (var unit in units) { center += unit.Unit.Position; } center /= units.Count; OffsetsUnitToCenter.Clear(); OffsetsUnitToCenter.Capacity = units.Count; foreach (var unit in units) { OffsetsUnitToCenter.Add(center - unit.Unit.Position); } OffsetCommanderToCenter = center - Commander.Unit.Position; } else { NewCommander = false; } }