Very Simple Unit Selection Button

This is a very simple way to select a unit. This doesn’t instantiate the buttons for units but it will easily switch between them.

First make a new script as below:

public class CharacterButtonUI : MonoBehaviour
{
    public void SwitchToCharacter(Unit unit)
    {
        List<Unit> friendlyUnits = UnitManager.Instance.GetFriendlyUnitList();
        foreach (Unit u in friendlyUnits)
        {
            if (u.unitData.name == unit.unitData.name)
            {
                UnitActionSystem.Instance.SetSelectedUnit(unit);
            }
        }
    }
}

Then assign this script to a button. After that, make a new OnClick() event for the button and assign the button itself to the empty space. Then choose the script and function from the dropdown menu and assign the unit you want this button to switch to. I would also recommend either putting a picture of that unit or adding a name.

The addition of the List<Unit> friendlyUnit will make sure that if the unit is dead, the player cannot select that unit.

Privacy & Terms