using UnityEngine;
public class CharactersSelector : MonoBehaviour
{
[SerializeField] private Transform _leftCharacterParent;
[SerializeField] private Transform _rightCharacterParent;
[SerializeField] private UICharacter _startUICharacter;
private void Awake()
{
SelectCharacter(_leftCharacterParent, _startUICharacter);
SelectCharacter(_rightCharacterParent, _startUICharacter);
}
public void SelectFirstCharacter(UICharacter UICharacter) => SelectCharacter(_leftCharacterParent, UICharacter);
public void SelectSecondCharacter(UICharacter UICharacter) => SelectCharacter(_rightCharacterParent, UICharacter);
private void SelectCharacter(Transform parent, UICharacter UICharacter)
{
ClearParentChilds(parent);
InstantiateCharacterOnParent(parent, UICharacter.gameObject);
}
private void ClearParentChilds(Transform parent)
{
foreach(Transform child in parent)
{
Destroy(child.gameObject);
}
}
private void InstantiateCharacterOnParent(Transform parent, GameObject UICharacterGameObject) => Instantiate(UICharacterGameObject, parent);
}