var enemyPrefab:GameObject;
var target:Transform;
var spawnDistance:float=10.0;
var spawnDelay:float=10.0;

private var enemy_spawn_Timer :float=0.0;
private var spawnFlag:boolean=false;



function Start(){
 
	target=gameObject.Find("player").transform;  
	
	spawn();
	
	
	
}


function Update(){



   checkTarget();
   
   if(spawnFlag==true){
        
	if(enemy_spawn_Timer >= spawnDelay ){
		enemy_spawn_Timer=0.0;	
	
		spawn();
   
	}
   enemy_spawn_Timer += Time.deltaTime;
   }
   

}

function checkTarget(){

           var difference = target.position - transform.position;
		   var   distance = difference.magnitude; 
		   
		   if(distance < spawnDistance){ spawnFlag=true; }
		   else  spawnFlag=false;
		   
}
function spawn(){

		if(enemyPrefab){
			Instantiate(enemyPrefab,transform.position,transform.rotation);     
        }


}

function OnDrawGizmos () {
    Gizmos.DrawIcon (transform.position, "Light Gizmo.tiff");
}