Hi All,
I’m trying to create a custom input manager, where I can change the input device on the fly. I’m not very experienced in Unity or C# so my angle/way to tackle the issue might not be the best…not to mention completely wrong.
The way I have set it up at the moment is that the player Script queries the InputManager.cs for input. The idea is that the input manager gathers the input from whatever device/control mapping that is choosen… and then the “player” can in turn access the input manager for the input.
Declaring the input devices:
//The Joystick
private JoystickScript theJoystick;
private GameObject theJoystickGameObject;
//The Keyboard
private KeyboardInputScript theKeyboard;
private GameObject theKeyboardGameObject;
Hook them up:
//Find it by name
currentInputDeviceGameObject = GameObject.Find("Joystick");
//"create" a pointer to it
theJoystick = currentInputDeviceGameObject.GetComponent<JoystickScript>();
Get Input:
void Update()
{
//Get the input from the joystick
y=theJoystick.inputY;
}
Change a input device:
void SetInputDevice(inputDeviceType theNewInputDevice)
{
Do stuff
}
The way I access the input in the update function is not flexible, as the component type needs to be determined i.e (JoystickScript or KeyboardScript)
I prefer not to be checking which device to select the input from in the update function with a conditional statement/switch as that would be a waste of “time”.
Any suggestions on how I could access the input in the update function in a more flexible way…so instead of “joystick.inputX” i could have “inputDevice.inputX” where the input device can be switched to accelerometer/mouse/keybpard etc…
Maybe I’m on the wrong path of to setup something like this in a good manner…
As I mentioned I’m quite new to unity so I have’t reached the enlightened state of knowing the best design patterns and practices to put together something in unity, any help would be much appreciated.
Thanks in advance!