- Home /
question about arrays
I was told to read about arrays, and so I did, but they are a bit confusing. How would I make an Input field that dumps the inputted value to a slot in an array, then randomly chooses array slot?
Answer by look001 · Jan 18, 2018 at 04:30 PM
There are arrays and Lists. Arrays have no dynamic size. Therefore you need to specify the max of entries before. Lists work with pointers so each entry item points on the next one in the row. Therefore the size is dynamic. For your problem i recommend using a list. Here is an example with an Input field (edited from docs):
public InputField mainInputField;
List<string> inputs = new List<string> ();
// Checks if there is anything entered into the input field.
void LockInput(InputField input)
{
if (input.text.Length > 0)
{
Debug.Log("Text has been entered");
inputs.Add (input.text);
}
else if (input.text.Length == 0)
{
Debug.Log("Main Input Empty");
}
}
public void Start()
{
//Adds a listener that invokes the "LockInput" method when the player finishes editing the main input field.
//Passes the main input field into the method when "LockInput" is invoked
mainInputField.onEndEdit.AddListener(delegate {LockInput(mainInputField); });
}
Your answer
Follow this Question
Related Questions
C# Random spawn from an array 0 Answers
Referencing private string for array name 2 Answers
Beginner : Random gameobject from array 2 Answers
Writing to GUI from an array 0 Answers
can you instantiate random prefabs from the resource folder? 2 Answers