Home > other >  InputField array is a single instance of the problem
InputField array is a single instance of the problem

Time:09-18

Private InputField [] InpPos=new InputField [4].

InpPos [I]=but before must instantiate the single variable

This zha instantiation

Can't write InpPos [I]=new InputField (); An error

CodePudding user response:

Because the UI interaction control of the core script itself is not a visible UI elements, must be combined with one or more visual UI elements to display, so its Unity regulation is can't be instantiated publicly, so can only be loaded from the resources, you can use GetComponentsInChildren<> Analysis the InputField so as to get all the assignment,
For example:
For (int I=0; I & lt; InputFields. Length; I++) {
InputFields [I]=GetComponentsInChildren (a) [I];
}
To note is that GetComponentsInChildren testing began from itself, and downward detection according to the order of the Hierarchy

CodePudding user response:

You can build InputField in the editor, and then drag your array

CodePudding user response:

New Class []
Create the array object

Array object needs to be specified when creating the size, but inside the types are the default values, if it is a class that is null,
Need to once again set value

You may also directly bring a new class [] {new class (), new class (),... }; Directly to initialize the members in the array

If it is the Unity of the Component object, a new Component that nobody do because all the components are on the GameObject you need to use GetComponent method such as access to set into the array, of course, also can through to define an array of public to drag out in the interface to operate fill values

CodePudding user response:

Copy a ready-made with how many how many times will copy with Instantiate (); so easy

CodePudding user response:

Can also be created dynamically, and then getComponent, access to the InputField, then assignment

CodePudding user response:

Inside the for loop is initialized
  • Related