var bulletActive:boolean=true;
var bulletStyle :int=0;
var bulletSpeed:float;
var bulletNumber:int;
var fireDelay:int;
var bulletPrefab:GameObject;
var target:Transform;
var attackDistance:float;

private var shootFlag:boolean =false;
private var weapon_Fire_Timer : float = 0.0;	


function Update () {




	if( bulletActive){
   
   
   
       checkTarget();
   
 
       if(shootFlag==true) {
	   
			if(weapon_Fire_Timer >= fireDelay){
             
			 weapon_Fire_Timer = 0.0;
	   
				switch (bulletStyle){
		
				case 0: shoot(); break;
		
				case 1:way3Shoot();break;
		
				case 2:way12Shoot();break;
         
				case 3:roundShoot();break;
			}
	   
	   
	   }
	   
	    weapon_Fire_Timer += Time.deltaTime;
	}
   
   
	}


}
function checkTarget(){

           var difference = target.position - transform.position;
		   var   distance = difference.magnitude; 
		   
		   if(distance < attackDistance  &&  distance >3.0){ shootFlag=true; }
		   else  shootFlag=false;;
		   

}
function shoot(){

        
			 
			 if(bulletPrefab){

			var difference = target.position - transform.position; 
			
			var direction = transform.TransformDirection(difference.normalized);
			var instantiatedProjectile : GameObject = Instantiate( bulletPrefab,transform.position,transform.rotation);
			instantiatedProjectile.transform.LookAt(target);
			
		
             
			 }
			
}

function way3Shoot(){


           if(bulletPrefab){

			var instantiatedProjectile : GameObject = Instantiate( bulletPrefab,transform.position,transform.rotation);

			instantiatedProjectile.transform.LookAt(target);
            var instantiatedProjectile1 : GameObject = Instantiate( bulletPrefab,transform.position,transform.rotation);
		    instantiatedProjectile1.transform.LookAt(target);
			instantiatedProjectile1.transform.Rotate(8,0,0);

			var instantiatedProjectile2 : GameObject = Instantiate( bulletPrefab,transform.position,transform.rotation);
            instantiatedProjectile2.transform.LookAt(target);
			instantiatedProjectile2.transform.Rotate(-8,0,0);
           }
		   
		
}

function way12Shoot(){


			if(bulletPrefab){

			var instantiatedProjectile : GameObject = Instantiate( bulletPrefab,transform.position,transform.rotation);

			instantiatedProjectile.transform.LookAt(target);
            var instantiatedProjectile1 : GameObject = Instantiate( bulletPrefab,transform.position,transform.rotation);
		    instantiatedProjectile1.transform.LookAt(target);
			instantiatedProjectile1.transform.Rotate(30,0,0);

			var instantiatedProjectile2 : GameObject = Instantiate( bulletPrefab,transform.position,transform.rotation);
            instantiatedProjectile2.transform.LookAt(target);
			instantiatedProjectile2.transform.Rotate(60,0,0);
			
			var instantiatedProjectile3 : GameObject = Instantiate( bulletPrefab,transform.position,transform.rotation);
		    instantiatedProjectile3.transform.LookAt(target);
			instantiatedProjectile3.transform.Rotate(90,0,0);

			var instantiatedProjectile4 : GameObject = Instantiate( bulletPrefab,transform.position,transform.rotation);
            instantiatedProjectile4.transform.LookAt(target);
			instantiatedProjectile4.transform.Rotate(120,0,0);
			
			var instantiatedProjectile5 : GameObject = Instantiate( bulletPrefab,transform.position,transform.rotation);
		    instantiatedProjectile5.transform.LookAt(target);
			instantiatedProjectile5.transform.Rotate(150,0,0);

			var instantiatedProjectile6 : GameObject = Instantiate( bulletPrefab,transform.position,transform.rotation);
            instantiatedProjectile6.transform.LookAt(target);
			instantiatedProjectile6.transform.Rotate(180,0,0);
			
			var instantiatedProjectile7 : GameObject = Instantiate( bulletPrefab,transform.position,transform.rotation);
		    instantiatedProjectile7.transform.LookAt(target);
			instantiatedProjectile7.transform.Rotate(210,0,0);

			var instantiatedProjectile8 : GameObject = Instantiate( bulletPrefab,transform.position,transform.rotation);
            instantiatedProjectile8.transform.LookAt(target);
			instantiatedProjectile8.transform.Rotate(240,0,0);
			
			var instantiatedProjectile9: GameObject = Instantiate( bulletPrefab,transform.position,transform.rotation);
		    instantiatedProjectile9.transform.LookAt(target);
			instantiatedProjectile9.transform.Rotate(270,0,0);

			var instantiatedProjectile10 : GameObject = Instantiate( bulletPrefab,transform.position,transform.rotation);
            instantiatedProjectile10.transform.LookAt(target);
			instantiatedProjectile10.transform.Rotate(300,0,0);
			
			var instantiatedProjectile11 : GameObject = Instantiate( bulletPrefab,transform.position,transform.rotation);
		    instantiatedProjectile11.transform.LookAt(target);
			instantiatedProjectile11.transform.Rotate(330,0,0);

			
           }

}

function roundShoot(){


           if(bulletPrefab){

			var instantiatedProjectile : GameObject = Instantiate( bulletPrefab,transform.position,transform.rotation);

			instantiatedProjectile.transform.LookAt(target);
            var instantiatedProjectile1 : GameObject = Instantiate( bulletPrefab,transform.position,transform.rotation);
		    instantiatedProjectile1.transform.LookAt(target);
			instantiatedProjectile1.transform.Rotate(8,0,0);
            yield WaitForSeconds(0.1);
			
			var instantiatedProjectile2 : GameObject = Instantiate( bulletPrefab,transform.position,transform.rotation);
            instantiatedProjectile2.transform.LookAt(target);
			instantiatedProjectile2.transform.Rotate(16,0,0);
           yield WaitForSeconds(0.1);
		    var instantiatedProjectile3 : GameObject = Instantiate( bulletPrefab,transform.position,transform.rotation);
		    instantiatedProjectile3.transform.LookAt(target);
			instantiatedProjectile3.transform.Rotate(24,0,0);
			yield WaitForSeconds(0.1);
		
			var instantiatedProjectile4 : GameObject = Instantiate( bulletPrefab,transform.position,transform.rotation);
            instantiatedProjectile4.transform.LookAt(target);
			instantiatedProjectile4.transform.Rotate(32,0,0);
			yield WaitForSeconds(0.1);    
		   
		   var instantiatedProjectile5 : GameObject = Instantiate( bulletPrefab,transform.position,transform.rotation);
		    instantiatedProjectile5.transform.LookAt(target);
			instantiatedProjectile5.transform.Rotate(24,0,0);
			yield WaitForSeconds(0.1);
		   
		   var instantiatedProjectile6 : GameObject = Instantiate( bulletPrefab,transform.position,transform.rotation);
            instantiatedProjectile6.transform.LookAt(target);
			instantiatedProjectile6.transform.Rotate(16,0,0);
			yield WaitForSeconds(0.1);   
           
		   var instantiatedProjectile7 : GameObject = Instantiate( bulletPrefab,transform.position,transform.rotation);
		    instantiatedProjectile7.transform.LookAt(target);
			instantiatedProjectile7.transform.Rotate(8,0,0);
			yield WaitForSeconds(0.1);
		  
		   
		   
		   }
		   
		   
		   
		   
		   
		
}