- Home /
Edit AnimationClip during runtime from script
Hi all!
TL;DR - How do you change the values of keyframes in an AnimationClip from a script.
I'm working on a project that is progressing nicely, and is at the point of getting a bit of polish here and there. One of the big pieces of polish, is to stop changing transforms, colors, etc directly from scripts with no transitions to make them look nice, to instead using Mecanim/Animators to get some nice animations happening (triggered by the existing logic in C# scripts).
The problem we are running into is our animation states have a slight context to them, that's looking like it will require many MANY animation states to get it working right.
An example scenario might be:
Say we have a button that is flashing due to an animation state. - Flash_State.
When you mouse over this button, it changes state to an animation that makes it red currently. - Highlighted_State.
Pretty simple with Mecanim right? Just some simple transition conditions. No worries.
Now, if the Text on that button says "Hello", the Highlight_State transitions the button to become red, as it does. Now if the button was instead saying "Goodbye", and you want that same Highlight_State to instead make it green, which it wasn't setup for, how would you do this? (Assuming using another clip wasn't an option!)
I am over-simplifying what we are actually doing, but I figured this was a lot more straight forward to explain.
Is there a way to access the KeyFrames of the animation clip, and in this example, change the value of the color attribute that is being changed?
If not, is there something key to working in Mecanim that I've just missed?
~
Thanks all!
~
Your answer
Follow this Question
Related Questions
Is there a way to change the WrapMode of all Animations in a Mecanim Animator? 1 Answer
Duplicating animation clip keyframe behaviour in multiple clips 0 Answers
animation to animator [mecanim] 1 Answer
Imported model partially disappears 2 Answers
Can the mecanim animators Controller var be set in code? 1 Answer