#pragma strict

var playerNumber : int =1;
var isChecking : boolean = false;
var currentJoystick;
var player = new Array(0,0,0,0);
var fu : boolean;
function Start () {
	StartCoroutine ("CheckInput");
}

function CheckInput () {
		// requires you to set up axes "Joy0X" - "Joy3X" and "Joy0Y" - "Joy3Y" in the Input Manger
		while(playerNumber<5){
		
			print("ich geh");
			yield WaitForEndOfFrame();
			while(isChecking){
			fu = true;
			print("ich bin in der while schleife");
				for (var i : int = 0; i < 11; i++) {
				
					if (Mathf.Abs(Input.GetAxis("Vertical"+i)) > 0.2 || Mathf.Abs(Input.GetAxis("Horizontal"+i)) > 0.2){
						Debug.Log (Input.GetJoystickNames()[i]+" is moved");
						player[1]=i;
					}else if(!isChecking){
					playerNumber++;
					}
				}
			}
			
		if(fu){
		print("hier");
		playerNumber++;
		fu=false;
		}
		}
	}
	
	function Update(){
	
			if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.2 || Mathf.Abs(Input.GetAxis("Horizontal")) > 0.2){
				isChecking=true;
			}else{
				isChecking=false;
			}
	print(isChecking);
	print(playerNumber);
	for( var i : int=0; i<3;i++){
		print(player[i]);
	}
	}


	function OnGUI () {
	
	GUI.Box (Rect (30,60,1000,50), "Player" + playerNumber +  "use left Joystick" );
 
 }