-
Notifications
You must be signed in to change notification settings - Fork 33
IsPluggedIn
Will always return false
on other platforms (including web platforms).
public static bool IsPluggedIn(XboxController controllerNumber)
[System.Obsolete] public static bool IsPluggedIn(int controllerNumber)
IsPluggedIn()
returns true
if the specified XboxController
is currently plugged in.
Please note that this method only works on Windows because it utilizes functionality from XInput.NET that Unity doesn't provide natively. On other platforms, this method will always return false
.
There is a deprecated version of this method that takes in an int
between 1 to 4, representing controller numbers. It is discouraged to use this version. Passing any int value other than 1 to 4 will default in checking if controller 1 is connected.
-
XboxController controllerNumber
: An identifier for the specific controller. IfXboxController.Any
is provided, XCI will check if any of the controllers are plugged in. Please refer to XboxController for all possible controllers.
The example demonstrates checking if controller 1 and controller 2 are plugged in. If they are, the Unity Console will print that the controllers are ready.
using UnityEngine;
using XboxCtrlrInput;
public class TestScript : MonoBehavior
{
void Start()
{
// XCI.IsPluggedIn() only works on Windows
if( Application.platform == RuntimePlatform.WindowsPlayer ||
Application.platform == RuntimePlatform.WindowsEditor )
{
if( XCI.IsPluggedIn(XboxController.First) )
{
Debug.Log("Player 1 is ready!");
}
if( XCI.IsPluggedIn(XboxController.Second) )
{
Debug.Log("Player 2 is ready!");
}
}
}
}