Home > Blockchain >  How to add object in SerializeField in Uinty3D using C#
How to add object in SerializeField in Uinty3D using C#

Time:07-13

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
}

CodePudding user response:

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