How to create animations that can be edited with scripts in runtime?

Okay, let’s make it simple.
I have 3 objects (A,B,C) on a plane. I made a script that permits me to swap their position with the mouse, so I can drag an object over another one, and swap their position.

This is very easy to accomplish with a script.
But how to do it if I want an animation?

When I create an animation, I can define a starting position, and I final position, following a curve. I want to be able to change the final position in runtime, so I don’t have to be worried where is the other player to swap, I can be sure to have that animation with that curve, from A to B or C.

Can you help me to accomplish this very simple task?

I can use timelines, if needed.

Working on Unity 2018.2.1f1.

Thank you.

One suggestion is to use AnimationCurves to store the animation data in your script. You can copy and edit them at runtime to modify the final position.