I need to change different properties of states in Mecanim at runtime(Mainly animation-speed and animation-clips). I found a way to make it work:
UnityEditorInternal.AnimatorController ac = animator.runtimeAnimatorController as UnityEditorInternal.AnimatorController; UnityEditorInternal.StateMachine sm = ac.GetLayer(0).stateMachine; //set the animationclip to the one that is set for the current attack sm.GetState(1).SetAnimationClip(animationClipToolStart); sm.GetState(2).SetAnimationClip(animationClipToolEnd); //set the speed of the animation so that it ends when startupTime is over sm.GetState(1).speed =(float)(animationClipToolStart.length/startupTime); sm.GetState(2).speed =(float)(animationClipToolEnd.length/cooldownTime);
It works fine inside the Editor. However, when I try to Build it, I get the error that the UnityEditorInternal Namespace was not found(which makes sense, because Unity probably doesn’t export the Editor features for the final game). Therefore, I wanted to ask if there is a way around this error-message, or if someone has an idea for a good alternative.