Answer the question
In order to leave comments, you need to log in
Is it normal to split everything into so many methods?
There is this code:
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);
}
Answer the question
In order to leave comments, you need to log in
looks good except for unused methods.
Better that than piling up code.
One tells me that it is necessary that there are few methods, and the other that there are many.
I usually divide into classes and divide them into layers, I paint the bottom layer into objects to the maximum, the layers above, group the objects (they use the bottom ones as libraries), as a result, having created the bottom layer once, you can not be distracted by it and use the methods of the top-level classes.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question