- Home /
Passing multiple parameters into InputField AddListener
I have a total of 12 InputFields that can take in decimal values, each meant to change an individual stat of an object. Because each InputField needs to affect something different, I need a way to identify which InputField will change which stat.
I thought about using InputField's onEndEdit.AddListener but this AddListener only accepts a method with a string argument, which I need to hold the decimal values. Is there a way to override the AddListener to accept two parameters instead, one for the decimal values and another that holds an enum value, for example.
Or is there a better method to accomplish this?
Answer by xxmariofer · Nov 29, 2019 at 08:12 AM
what i would do is something like this
first create the struct with the values you need (i am using float and enum just as an example)
public struct InputItem
{
Body body;
float yourNumber;
}
public enum Body
{
head,
shoulder,
eyes
}
now create a list with a list that will have a InputItem per inputfield
public List<InputItem> listOfInputs = new List<InputItem>();
and add to the listener the index that the field has in the array, and you can access to the value of the input and body part or the number
public void InputListener(int index)
{
listOfInputs[index].etc.....
}
Your answer
