I am making a VR unity project, however since I don't own a VR headset, the headset is my phone in a cardboard box, and I am receiving input from an xbox controller. When I connect the xbox controller to my laptop, it works fine with the game, but when I connect it to the phone, it connects at first, but after two seconds disconnects. I am using unity remote 5, I have an iPhone 13 Pro, and my unity editor version is 2022.3.9f1
I used this code to detect if the controller is connected or not:
private bool connected = false;
IEnumerator CheckForControllers() {
while (true) {
var controllers = Input.GetJoystickNames();
if (!connected && controllers.Length > 0) {
connected = true;
Debug.Log("Connected");
} else if (connected && controllers.Length == 0) {
connected = false;
Debug.Log("Disconnected");
}
yield return new WaitForSeconds(1f);
}
}
void Awake() {
StartCoroutine(CheckForControllers());
}
This is what the console shows when the phone is connected: enter image description here And this is what it says when the phone is not connected (I waited for 30 seconds before stopping the program): enter image description here
I used this code to detect if the controller is connected or not:
private bool connected = false;
IEnumerator CheckForControllers() {
while (true) {
var controllers = Input.GetJoystickNames();
if (!connected && controllers.Length > 0) {
connected = true;
Debug.Log("Connected");
} else if (connected && controllers.Length == 0) {
connected = false;
Debug.Log("Disconnected");
}
yield return new WaitForSeconds(1f);
}
}
void Awake() {
StartCoroutine(CheckForControllers());
}
This is what the console shows when the phone is connected: https://i.stack.imgur.com/cA5BQ.png And this is what it says when the phone is not connected (I waited for 30 seconds before stopping the program): https://i.stack.imgur.com/xaa2O.png