La UI puede crearse dinámicamente desde código.
Ejemplo: generar botones, slots o entradas de una lista.
[SerializeField]
private GameObject prefabSlot;
[SerializeField]
private Transform contenedor;
GameObject slot = Instantiate(
prefabSlot,
contenedor
);
TMP_Text texto =
slot.GetComponentInChildren<TMP_Text>();
texto.text = "Espada";
foreach (Transform hijo in contenedor)
{
Destroy(hijo.gameObject);
}
foreach (Item item in inventario)
{
GameObject slot =
Instantiate(
prefabSlot,
contenedor
);
TMP_Text texto =
slot.GetComponentInChildren<TMP_Text>();
texto.text = item.nombre;
}
Instantiate(prefab, parent)
GetComponentInChildren<T>()
Destroy(...)