/*
This is a demo project to show use of BroadcastMessage.  The control inputs
*/

#pragma strict
var cubeController : GameObject;
private var controlInputs : Vector2;

function Start () {

}

function Update () {
	var inputThisFrame : boolean = false; //used to decide if we should broadcast the inputs (only broadcast when there are inputs)
	
	//are there any horizontal inputs?  these can be made with the arrow keys
	if(Input.GetAxis("Horizontal") < 0) {
		controlInputs.x = -1;
		inputThisFrame = true;
	}
	else if(Input.GetAxis("Horizontal") > 0) {
		controlInputs.x = 1;
		inputThisFrame = true;
	}

	//are there any vertical inputs?  these can be made with the arrow keys
	if(Input.GetAxis("Vertical") < 0) {
		controlInputs.y = -1;
		inputThisFrame = true;
	}
	else if(Input.GetAxis("Vertical") > 0) {
		controlInputs.y = 1;
		inputThisFrame = true;
	}
	
	if(inputThisFrame) {
		//the player is making an input...broadcast that input to the cube controller
		cubeController.BroadcastMessage("ApplyInputs", controlInputs);
	}
	
}