Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

IsPluggedIn

Jibran Syed edited this page Jun 27, 2017 · 1 revision

<- Back to Coding References

Attention: WINDOWS ONLY

Will always return false on other platforms (including web platforms).

Signature

public static bool IsPluggedIn(XboxController controllerNumber)
[System.Obsolete] public static bool IsPluggedIn(int controllerNumber)

Description

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.

Parameters

  • XboxController controllerNumber : An identifier for the specific controller. If XboxController.Any is provided, XCI will check if any of the controllers are plugged in. Please refer to XboxController for all possible controllers.

Example

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!");
            }
        }
    }
}

<- Back to Coding References

Clone this wiki locally