Files
findthesource/Assets/Scripts/ControllerHandler.cs

39 lines
1.1 KiB
C#
Raw Normal View History

2023-04-05 11:08:29 +02:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ControllerHandler : MonoBehaviour
{
[SerializeField]private bool connected = false;
public string[] controllers;
private IEnumerator detectControllers(){
while(true){
controllers = Input.GetJoystickNames();
if(!connected && controllers.Length > 0){
Debug.Log("Controller connected");
for(int i = 0; i < controllers.Length; i++){
Debug.Log(controllers[i]);
2023-04-14 20:21:47 +02:00
//lock and disable mouse
//Cursor.lockState = CursorLockMode.locked;
//Cursor.visible = false;
2023-04-05 11:08:29 +02:00
//yield break;
}
}else if(connected && controllers.Length == 0){
Debug.Log("disconnected / not connected");
}else if(!connected && controllers.Length == 0){
Debug.Log("not connected");
}
2023-06-12 13:05:47 +02:00
yield return new WaitForSecondsRealtime(5f); //check every 5 seconds
2023-04-05 11:08:29 +02:00
}
}
private void Awake() {
StartCoroutine(detectControllers());
}
}