Character selection

Hello, does anyone know how to make a character selection like the one in the Ballz mobile game?
I have watched a YouTube tutorial on how to do it and came up with this script :

private List<GameObject> balls;
private int selectionIndex = 0;

private void Start()
{
    balls = new List<GameObject>();
    foreach(Transform t in transform)
    {
        balls.Add(t.gameObject);
        t.gameObject.SetActive(false);

    }

    balls[selectionIndex].SetActive(true);
}

private void Update()
{
    
}

public void Select(int index)
{
    if (index == selectionIndex)
        return;

    if (index < 0 || index >= balls.Count)
        return;

    balls[selectionIndex].SetActive(false);
    selectionIndex = index;
    balls[selectionIndex].SetActive(true);
}

Now, instead of the gameobjects to get inactive, what I want instead is to change the outline color of the gameobjects and change a text inside the gameobject. How would I do that? I’m still new to coding and have no idea.

Most likely you’d like to add a component to the balls, something like BallSelectionBehaviour.

In that script you could have a public method called OnBallSelected(), where you’d do everything that you want, including the SetActive().

And finally, in your script, you would call balls[selectionIndex].GetComponent<BallSelectionBehaviour>.OnBallSelected() instead of the set active.

Note that GetComponent<> can get a bit heavy. It might be a good idea to store the BallSelectionBehaviour in a list, just like you did with the GameObject, and populate the list only once on Start. Another option would be a Dictionary<GameObject, BallSelectionBehaviour>.

From what I see, I’d also create a OnBallDeselected() and add there the SetActive(false). It is a good idea to have your things separated. So, next time you want to add some particles, e.g., when a ball is selected, you know exactly where to change the code.