I'm not sure if that's possible to be honest, but if you want something completely dynamic, why not make a script that handles the animation itself?
Here's an example:
public Vector3 startPosition;
public Vector3 endPosition;
float counter = 1f;
public Update() {
if (counter <= 0f) {
// Replace 1.0f with another number to change animation's speed
counter -= 1.0f -Time.deltaTime;
/* Replace `position` with `localPosition`, if you would
* like your animation to take place in local space,
* instead of world space
*
* This is doing linear interpolation, if you would like to do
* something more fancy, you can tweak `counter`, search for
* "easing functions" for more info
*/
transform.position = Vector3.Lerp(startPosition, endPosition, counter);
}
}
public Animate() { counter = 0f; }
Add this in a class, make sure to add additional data like rotation or scale (if you want). Attach the script to any object that you want to animate, then change the startPosition
and endPosition
from the Inspector (or from a script, if the object is also made dynamically) for each individual object. Even though all objects are doing the same animation, they are moving to different locations.
Edit:
To support RectTransform
you use the same logic, but you have to play with its anchor, pivot and position. You can read Unity's RectTransform API, but also make sure to read Unity: Designing UI for Multiple Resolutions, which can help you understand which specific value to animate and why (to appear properly on different screen sizes).