[Resolved] Selection Box is not selecting units for client

Hello. I seem to be missing something from the lectures.
Everything is working properly for the host, be it in the built version or in the Unity Editor.
But when I connect as a client, again, doesn’t matter if it’s in the build or editor, the selection box doesn’t select any units.
Here is my code for box selection, which seems identical to the one in the lectures.

Vector2 min = unitSelectionArea.anchoredPosition - (unitSelectionArea.sizeDelta / 2);
Vector2 max = unitSelectionArea.anchoredPosition + (unitSelectionArea.sizeDelta / 2);
foreach (var unit in player.GetMyUnits())
{
            if (SelectedUnits.Contains(unit)) continue;
            Vector3 screenPosition = mainCamera.WorldToScreenPoint(unit.transform.position);
            if (screenPosition.x > min.x
                && screenPosition.x < max.x
                && screenPosition.y > min.y
                && screenPosition.y < max.y)
            {
                SelectedUnits.Add(unit);
                unit.Select();
            }
}

Could I get some help, or is anyone getting the same issue?

Edit: I just had the names of these two methods mixed up, fixing them fixed the issue

void AuthorityHandleUnitSpawned(Unit unit)
{
        if (!hasAuthority) return;
        myUnits.Add(unit);
}

void AuthorityHandleUnitDespawned(Unit unit)
{
        if (!hasAuthority) return;
        myUnits.Remove(unit);
}
2 Likes

Privacy & Terms