Mecanim control animation frames via script?

is it possible to set the displayed frame via float?

like if a sphere is comming closer to an cube. I measure the distance to the sphere via script. if the sphere is like 10 units away it should show the frame 10 of the cubs animation. if its like 30 units away it should show the frame 30.

if its possible please tell me how I can do this. the example above is just for explanation. it would be to complicated to explane for what purpose I need the info but it would be a very important for my game and I could not do what I want to do in my game without it.

animator.ForceStateNormalizedTime(1.0);

Animator.ForceStateNormalizedTime

ForceNormalizedTime is deprecated in Unity 5. I am posting the simple solution I am using here in case anyone is interested:

//This will seek to the middle of the animation
animator.Play(“yourcurrentstate”, -1, 0.5f);
animator.speed = 0f;