How to apply one code for all animations?

I have animation. When it ends, I play it again in the revert direction with the code:

animation["boxOpen1"].speed = -1.0f;
animation["boxOpen1"].time = animation["boxOpen1"].length;

But I need to use this code with animations boxOpen[1-10] for different objects and I can’t write code animation.speed = -1.0f;
And I can’t call all animations boxOpen1, because they must have unique name. How can I use this code for all animations?

Make “boxOpen1” a public string so every object can have its own animation name.

As a suggestion try out the unity mecanim system.