Head bob script accelerating unexpectedly

Hi everyone, I have this head bob scrip that I got off of Unify community Wiki, but it is accelerating unexpectedly. Worse, it seems to be happening at random, so it's hard to test for. Any help would be appreciated. Here is the code:

private var timer = 0.0; 
var bobbingSpeed = 0.18; 
var bobbingAmount = 0.2; 
var midpoint = 2.0; 

function Update () { 
   waveslice = 0.0; 
   horizontal = Input.GetAxis("Horizontal"); 
   vertical = Input.GetAxis("Vertical"); 
   if (Mathf.Abs(horizontal) == 0 && Mathf.Abs(vertical) == 0) { 
      timer = 0.0; 
   } 
   else { 
      waveslice = Mathf.Sin(timer); 
      timer = timer + bobbingSpeed; 
      if (timer > Mathf.PI * 2) { 
         timer = timer - (Mathf.PI * 2); 
      } 
   } 
   if (waveslice != 0) { 
      translateChange = waveslice * bobbingAmount; 
      totalAxes = Mathf.Abs(horizontal) + Mathf.Abs(vertical); 
      totalAxes = Mathf.Clamp (totalAxes, 0.0, 1.0); 
      translateChange = totalAxes * translateChange; 
      transform.localPosition.y = midpoint + translateChange; 
   } 
   else { 
      transform.localPosition.y = midpoint; 
   }
}

That code isn't framerate-independent; you'd have to fix it so it is, by using Time.deltaTime appropriately.

I was having the same problem. I changed the Update function to FixedUpdate so it is no longer framerate dependent.