user17765346
user17765346

Reputation:

How to add object in SerializeField in Uinty3D using C#

I'm adding TMP_InputFields as a child with button using Instantiate. I have SeriazlizeField and it contains those input fields. How can I manage to add those new added input fields in this serializefield via script. Here's my code:

public GameObject settings;
public TMP_InputField addedPlayer;
public static int playerCount = 5;

[SerializeField]
public TMP_InputField[] names;

public void Plus(){
    playerCount++;
    TMP_InputField added = Instantiate(addedPlayer, settings.transform);
    added.name = "Name" + playerCount;
    //How to add this new added objects in names field
}

Upvotes: 0

Views: 41

Answers (1)

Morion
Morion

Reputation: 10860

  • replace TMP_InputField[] with the List<TMP_InputField>
  • use names.Add(yourInstantiatedObject)

Upvotes: 1

Related Questions