- Home /
Can I override keyframe values from code?
Hello!
I am trying to figure out if I can do the following:
I want to set up an animation that has special keyframes whose values I could then override from code.
As an example let's say I've got a sprite jump animation so I animate the transform so the Y = 1 at the peak of the jump.
Now let's say I want to use this animation on other sprites too but I want to vary the height of the jump.
What I am trying to do is write a little component where I can define a keyframe to be overriden in the editor and a value to override it with and then at component initialisation do that override on the specific animation defined by this component.
I've been looking at the documentation and this feels like it should be possible as based on this it looks like you can index to keyframes on curves and get to their value from code
http://docs.unity3d.com/ScriptReference/Keyframe-value.html
So I should be able to set keyframe values from code.
But that's as far as I am getting. Not sure how I can drill down to the keyframe I need as I am not sure how I can reference a specific animation track (or curve) from code or, better yet, meaningfully expose it in the inspector.
Has anyone done something like this and have you got any suggestions to share?
Many thanks!