I am working in Unity but I guess the same applies to C# in general.
this is a class I made:
public class KeyboardInput
{
private string name;
private KeyCode btn;
public KeyboardInput(string buttonName, KeyCode button)
{
name = buttonName;
btn = button;
}
}
When I create an instance of the class, if I don't specify the values required by the constructor, I will get an error.
Now I want to create an array of the class and I want to specify the values, but how ?
This seems to be working fine without specifying the values
public class InputController
{
private KeyboardInput[] defaultKeyBinding = new KeyboardInput[4];
public InputController()
{
for (int i = 0; i < defaultKeyBinding.Length; i++)
{
//Something inside here
}
}
}
I can tweak the code to be able to set the values inside the for loop, but I am very curious to know if there is a way!
defaultKeyBinding[i] = new KeyboardInput(string, KeyCode)?