- Home /
How can I add an Input Axis from a script, input coming from an external program?
For my game, I have made a class that creates a server connection with an external C# Windows Presentation Foundation application. The external application is sending data to Unity in the format of strings of text.
In my case, the external program is sending multiple mouse input data, formatted like this:
"M0|2|-157"
where M0 signifies the ID of the mouse being moved, 2 and -157 being the deltaX and deltaY values. I extract the relevant information from those strings, put it in a bunch of variables and use it in the game.
I want to implement a script to add multiple input axes to the Unity Input class, with the information provided by the program, so that another might use my code by simply executing my script and accessing, for instance:
Input.GetAxis("Multiple Mouse 1 X")
or
Input.GetAxis("Multiple Mouse 3 ScrollWheel");
but I couldn't find anything about how to add axes through the code, and how to feed them with values of my own, not just create axes based on the keyboard input or mouse input, because that doesn't work for multiple mice.
Any help is appreciated. Please ask for clarifications if needed.
So just to make sure I have understood this correctly, you are trying to make a secondary mouse work in your unity project from a remote location?
I am not completely sure about this, I don't think it is possible to add axis during runtime, and also I don't understand for what purpose?
If it is because you want to apply your mouse movements to some GameObject's position in the game then you simply just apply it directly.
someGameObject.transform.Translate(2, -157, 0);
Axes are used to extract data from joystick, control pads, keyboards and mices more easily. If your already are receiving these values from a remote location then I don't see the purpose of creating axes runtime.
You could certainly create your own class with methods that mimic GetAxis():
$$anonymous$$yInput.GetAxis("$$anonymous$$ultiple $$anonymous$$ouse 1X");
Of course I can apply the movement as you described. $$anonymous$$y goal is to have a nicer interface to do so. I am receiving input data from somewhere else than through the Input class, and I wished to have it in the same place. As it turns out from docs and other people I talked to, it's actually not possible to change Input in any way, so I resolved to just make a new class like robertbu said. For now.
Your answer
Follow this Question
Related Questions
Add Cursor (Top-Down-Shooter) 1 Answer
Why is this script showing all keycodes except shift? 2 Answers
Strange increment counter 1 Answer
How can I access other scripts and their functions? 3 Answers
Accessing external scripts (yet again) 2 Answers