#pragma strict

var originPosition:Vector3;
var originRotation:Quaternion;
 
 var shake_decay: float;
 var shake_intensity: float;
 
 private var tmp_shake_decay : float;
 private var tmp_shake_intensity: float;
 
 //function OnGUI () {
 //    if (GUI.Button (Rect (20,40,80,20), "Shake")) {
 //        Shake();
 //    }
 //} 
 
 function Start() {
 
 	originPosition = transform.position;
    originRotation = transform.rotation;
 
 }
 
 function Update(){
     if(tmp_shake_intensity > 0){
         transform.position = originPosition + Random.insideUnitSphere * tmp_shake_intensity;
         transform.rotation =  Quaternion(
                         originRotation.x + Random.Range(-tmp_shake_intensity,tmp_shake_intensity)*.2,
                         originRotation.y + Random.Range(-tmp_shake_intensity,tmp_shake_intensity)*.2,
                         originRotation.z + Random.Range(-tmp_shake_intensity,tmp_shake_intensity)*.2,
                         originRotation.w + Random.Range(-tmp_shake_intensity,tmp_shake_intensity)*.2);
         tmp_shake_intensity -= tmp_shake_decay;
     }
     
     if (tmp_shake_intensity <= 0) {
	   transform.position = originPosition;
	   transform.rotation = originRotation;
	 }
 }
 
 function Shake(){
     
     
     tmp_shake_decay = shake_decay;
     tmp_shake_intensity = shake_intensity;
     
     //shake_intensity = .3;
     //shake_decay = 0.002;
 }