public var enemyActive :boolean=false;


var dataFile : TextAsset;
var animNames: String[];  

private var  dataPairs:Array;
private var motionFlag:boolean=true;
private var index:int;


function Awake ()
{

 
 
	animation.wrapMode = WrapMode.Loop;

	
	animation.Stop();
	//animation.Play("idle");
}

function Start() {

    var returnChar = "\n"[0];
    var commaChar = ","[0];

    var dataLines = dataFile.text.Split(returnChar);
    var buildDataPairs = new ArrayList();

    for (var dataLine in dataLines) {
        var dataPair = dataLine.Split(commaChar);
        buildDataPairs.Add(dataPair);
    }
    dataPairs = buildDataPairs.ToArray();
	
	
	
	 index=0;
	

   
}


function Update(){


			 
            
            if(enemyActive){
 			
			motionControl();
			 }
			
			 

}

function motionControl(){
			 
			 

         if( motionFlag==true){
			
            switch (dataPairs[index][0]){
			 
			 
			 case "anim":    animationMode(index);   break;
			 
			 
			 
			 case "move":   moveMode(index);       break;
			 
			 
			 
			 case "search":  searchMode(index);    break;
			 
			 
			
			 
			 }

		}
            

}





function animationMode(i:int){
motionFlag=false;

                   data=int.Parse(dataPairs[i][1]);
				   var delay:float=float.Parse(dataPairs[i][2]);
				   
				
animation.Blend(animNames[data]);
	
//		animation.CrossFade(animNames[i]);
		
//		animation.Blend(animNames[i], 0);
		
 
			yield WaitForSeconds(delay);
			  
			 motionFlag=true;
			 index++;   
return;
}


function moveMode( i:int){

              
                motionFlag=false;

                   data=int.Parse(dataPairs[i][1]);
				   var delay:float=float.Parse(dataPairs[i][2]);
				
			while(delay>0) {  

              
			  switch (data){
	
	
				case 0:   transform.position.y= transform.position.y + Mathf.PingPong(Time.time/5,0.3)-0.15;
				break;


              
				case 1:   transform.position.x= transform.position.x + Mathf.PingPong(Time.time/5,0.3)-0.15;
				break;
			  
			  
			  
				case 2:    transform.position.x= transform.position.x -Time.deltaTime*1.0;
				break;

			  
			  
				}
			  
			  
			  yield ;
			  
			  delay -=Time.deltaTime;
			  
			  
			}
			  
			 motionFlag=true;
			 index++;   
  



 
}


function searchMode( i:int){



return;
}
			 
			 
			 
			
			 

