var bulletSpeed: int;
var damage:int=10;
var explosion: Transform;



function Update () {



    
   
	var hit: RaycastHit;
	var layerMask= (1 << 9);
   
    if (Physics.Raycast (transform.position, Vector3.down,hit,2,layerMask)) {
	

	var distanceToGround = hit.distance;
		
		
		 if (hit.collider.gameObject.tag=="BG"){
		       if(distanceToGround>0.5){ transform.Translate( Vector3.down *  bulletSpeed * Time.deltaTime);}
			   else if(distanceToGround<0.5){transform.Translate( Vector3.right *  bulletSpeed * Time.deltaTime);}
			   
				}
		}else{transform.Translate( Vector3.down *  bulletSpeed * Time.deltaTime);}
	
				  transform.Translate(Vector3.right * bulletSpeed * Time.deltaTime) ; 
    




	Destroy(gameObject,5.0);




}



function OnTriggerEnter(  otherObject: Collider        ){

if(otherObject.gameObject.tag == "enemy"){

	
	var tempExplosion: Transform;
	
	tempExplosion = Instantiate(explosion, transform.position, transform.rotation);
	
	
		
	otherObject.gameObject.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
	

	
	Destroy(this.gameObject);
	
}

}