Unit Selection with buttons?

Rather than click on the character to select it, I want to make buttons to select each unit. I’ve worked ahead in the course and have seen how we instantiate buttons for each character’s actions. I’ve adapted the code as follows:

    }
    private void CreateUnitActionButtons()
    {
        foreach(Transform buttonTransform in characterActionButtonContainerTransform)
        {
            Destroy(buttonTransform.gameObject);
        }

        foreach(GameObject gameObject in characterGameObjectList)  //The array will have multiple functions, based on what unit we are selecting
        {

            Debug.Log(gameObject.name);
            Transform characterActionButtonTransform = Instantiate(characterActionButtonPrefab, characterActionButtonContainerTransform); //We create a button for each relevant section
            actionButtonUI = characterActionButtonTransform.GetComponent<CharacterActionButtonUI>();
            actionButtonUI.textMeshPro.text = gameObject.name;
            actionButtonUI.unitAttachedToButton = gameObject;

        }
        //Debug.Log(characterActionButtonUIList);
    }

The buttons are labelled properly, which means they are reading each unit properly. I don’t know how to send a signal back to the specific character, to indicate that when I click on their name, they should be selected.

Any advice, or hints on how to get started?

You don’t inform the Unit. What you can do is make SetSelectedUnit(Unit unit) on the UnitActionSystem public. Then you can just call it and pass the Unit to it.

1 Like

That was much easier than I thought. Thank you for your help :slight_smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms