- Home /
USB Controller Guidance
Hello!
Im trying to understand what it is exactly I need to do to get a USB Logitech gaming controller to function with Unity. Is it Joystick that runs the DPad and GetButton that can run the controller butters? Is there something I have to add in so the code will recognize that the controller is plugged in? Any particular commands I should learn about?
Thanks!
From my answer here : http://answers.unity3d.com/questions/489439/changing-first-person-controller-to-work-with-ouya.html
All the types of input are handled with the Input $$anonymous$$anager : http://docs.unity3d.com/Documentation/$$anonymous$$anual/Input.html
You set up axis and button inputs for each controller : Joystick Buttons (from a specific joystick): "joystick 1 button 0", "joystick 1 button 1", "joystick 2 button 0", ...
you build a test project, to check if the inputs are working : eg http://www.alucardj.net16.net/JoystickTest/JoystickTest.html
For example, here is a setup for the Input $$anonymous$$anager and a sample of script to use those inputs.
Input $$anonymous$$anager Settings :
Example Script :
function TriggerInputs()
{
var offset : float = 1.5;
// - Triggers -
if ( Input.GetAxis( "Left Trigger" ) > 0.02 )
{
leftTrigger.position.y = leftTriggerStartPos.y + ( offset * Input.GetAxis( "Left Trigger" ) );
SetRendererColour( leftTrigger.renderer, selectedColour );
}
else
{
leftTrigger.position.y = leftTriggerStartPos.y;
SetRendererColour( leftTrigger.renderer, defaultColour );
}
if ( Input.GetAxis( "Right Trigger" ) > 0.02 )
{
rightTrigger.position.y = rightTriggerStartPos.y + ( offset * Input.GetAxis( "Right Trigger" ) );
SetRendererColour( rightTrigger.renderer, selectedColour );
}
else
{
rightTrigger.position.y = rightTriggerStartPos.y;
SetRendererColour( rightTrigger.renderer, defaultColour );
}
}
function BumperInputs()
{
// - Left Bumper -
if ( Input.GetButton( "Left Bumper" ) )
{
SetRendererColour( leftBumper, selectedColour );
}
else
{
SetRendererColour( leftBumper, defaultColour );
}
// - Right Bumper -
if ( Input.GetButton( "Right Bumper" ) )
{
SetRendererColour( rightBumper, selectedColour );
}
else
{
SetRendererColour( rightBumper, defaultColour );
}
}
By the way, don't use my inputs! You should really setup an input for each joystick , eg :
joystick 1 button 5
joystick 3 button 1
etc etc
Your answer

Follow this Question
Related Questions
GameController Unity wrong Axis-Values 0 Answers
How can I able to get the Joystick movement values (Axis 6 and 7 ) in Android ..?, 0 Answers
keyboard commands to Joystik C# "Object reference not set to an instance of an object" 1 Answer
MobileSingleStickControl is not what I expected. 0 Answers
Joystick Character movement. 1 Answer