// The reference to the explosion prefab
var explosion : GameObject;
var timeOut = 3.0;
var ishit=0;
 var dir= "down";
 var speed=5;
 var accumy=0;
// Kill the rocket after a while automatically
function Start () {


 while(true)
    {
     
     
     if (dir=='down')
 {
 
  accumy+=1;
  y =  speed * Time.deltaTime;
  if ( accumy<60 )
  transform.Translate(0, 0.1 , 0); 
  else 
  {dir = 'up';accumy=0;}
  
 }
 else
 {
  accumy-=1;
  y =  -speed * Time.deltaTime;
  if ( accumy>-60 )
  transform.Translate (0, -0.1, 0); 
  else 
  {dir = 'down';accumy=0;}

 }
     
     
     
     yield;
    }



   // Invoke("Kill", timeOut);
}

function Awake()
{
  speed=5;
}

 function update() {
print('pppppppppppppppp');
 
 
 
 }
 
function OnCollisionEnter (collision : Collision) {
    // Instantiate explosion at the impact point and rotate the explosion
    // so that the y-axis faces along the surface normal
  
    ishit+=1;
    

    
    if (collision.collider!='Whole')
    {
    var contact : ContactPoint = collision.contacts[0];
    var rotation = Quaternion.FromToRotation(Vector3.up, contact.normal);
    Instantiate (explosion, contact.point, rotation);
 	
 	
 	
 	  if (ishit>5) 
    Kill (collision);    
	
	}
}
 
function Kill (collision) {
    // Stop emitting particles in any children
     var emitter : ParticleEmitter= GetComponentInChildren(ParticleEmitter);
     if (emitter){
       emitter.emit = false;
	}
	transform.DetachChildren();
 
     
    Destroy(gameObject,1);
}
 
 
 
   //GetComponent(SpriteRenderer).sprite = spriteImage;
    // Detach children - We do this to detach the trail rendererer which should be set up to auto destruct
    
 

 
 
//@script RequireComponent (Rigidbody)