vegpont
This commit is contained in:
33
Assets/Scripts/ControllerHandler.cs
Normal file
33
Assets/Scripts/ControllerHandler.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
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]);
|
||||
//yield break;
|
||||
}
|
||||
}else if(connected && controllers.Length == 0){
|
||||
Debug.Log("disconnected / not connected");
|
||||
}else if(!connected && controllers.Length == 0){
|
||||
Debug.Log("not connected");
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds(5f); //check every 5 seconds
|
||||
}
|
||||
}
|
||||
|
||||
private void Awake() {
|
||||
StartCoroutine(detectControllers());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user