#pragma strict
var leftMost: float;
var rightMost: float;
var topMost: float;
var bottomMost: float;
var speed:int;

function Start () {

}

function Update () {
	speed = Random.Range(5,20);
	transform.Translate(Vector3.right * speed * Time.deltaTime);
	transform.Rotate(Vector3.forward * 5 * Time.deltaTime);
	
	leftMost = Camera.main.ScreenToWorldPoint(Vector3(0,0,0)).x;
	rightMost = Camera.main.ScreenToWorldPoint(Vector3(Screen.width,0,0)).x;
	
	bottomMost = Camera.main.ScreenToWorldPoint(Vector3(0,0,0)).y;
	topMost = Camera.main.ScreenToWorldPoint(Vector3(0,Screen.height,0)).y;
	
	if(transform.position.x < leftMost){
		transform.position.x = rightMost;
	}
	
	if(transform.position.x > rightMost){
		transform.position.x = leftMost;
	}
	
	if(transform.position.y < bottomMost){
		transform.position.y = topMost;
	}
	
	if(transform.position.y  > topMost){
		transform.position.y = bottomMost;
	}

}

function OnCollisionEnter2D(otherObject: Collision2D){
	var count:int = 0;
	var hit : ContactPoint;
	
	if(otherObject.gameObject.tag == "AmmoBox"){
		this.gameObject.transform.rotation.z = 0;
		
	}else if(otherObject.gameObject.tag == "Target"){
		this.gameObject.transform.rotation.z = 0;
		otherObject.gameObject.rigidbody2D.AddForce(Vector3.right * 50);
	}
	
}