This doesnt sound like a good approach. Why not just create an animation in your modeling program? I have a feeling that switching out meshes constantly will be heavy, and honestly a lot more work in the end for you. But if you have your heart set on this method for whatever reason, a basic rundown will be this:
Create an array of type Mesh. Populate the array in the inspector.
Create a global int variable to track the current mesh index.
Create a function that will take the input ( maybe a bool, positive is true, negative is false) //ie. left arrow vs right arrow
Each time this function is called you increase or decrease you global index respectively.
Make sure the index is within the bounds of the array.
Finally apply the mesh[currentMeshIndex] to the mesh filter in question.
You may have to alter the collider as well to reflect the current mesh.
Here is the basic idea of the script. I did not test this, so there could be misspellings or other issues, this is more of an example than fully working code.
public Mesh[] meshes = null;
private int meshIndex = 0;
private MeshFilter meshFilter = null; //You will need to set this in Start() or make public
public void MyMeshAnimator(bool stepIsPositive)
{
if(meshes != null && meshFilter != null) // Null checks
{
if(stepIsPositive)
{
meshIndex++; //Increase the index
if(meshIndex == meshes.Length) meshIndex = 0; //Reset the index if out of bounds
}
else
{
meshIndex--; //Decrease the index
if(meshIndex == -1)meshIndex = meshes.Length - 1; //Reset the index if out of bounds
}
meshFilter.mesh = meshes[meshIndex];
}
}
Really the only thing missing here is the rate at which you change the mesh. Currently if you call this from update everyframe, it will go crazy!
I also suspect you may do this for more than just the legs, if so you will want to maybe create an enum that determines what animation mesh needs changing, then apply that logic to the above function. Happy coding.