c# - How would I go about getting the text from all input fields in a scene in Unity 5? -


as of right now, have 2 input fields , button in scene. when button clicked, retrieve contents of both input fields. can contents of each 1 separately adding same script twice on on click function of them button. however, want both input fields while using 1 script.

i've tried using getcomponents, bu guess i'm not understanding how works. assumed getcomponents input fields in scene , save them array. cycle through each index , text property of each input. incorrect?

thanks!

what can use getcomponentsinchildren... put gameobjects component inputfield inside parent game object, add script parent...

then like:

---edit: ok played little inputfields... if pay attention, inputfield has 2 children objects, 1 called "placeholder" , 1 called "text" , both of them have text component, have like:

list<string> textfrommyinputs = new list<string>();  void getalltextfrominputfields()     {      foreach(inputfield inputfield in gameobject.getcomponentsinchildren<inputfield>())     {         foreach (text text in inputfield.getcomponentsinchildren<text>())         {             if (text.gameobject.name != "placeholder")                 textfrommyinputs.add(text.text);         }     }      foreach (string s in textfrommyinputs)     {         debug.log(s);     } } 

already tested , it's working me....


Comments