- Home /
Can i use animatorOverrideController for multiple Gameobjects separately?
I have level with procedurally generated blocks where each of them has same animation controller. At specific condition, written in code, i want to change animation of the block, and after another condition return it to original animation. It is important, that each block has own behaviour.
For now i can see that animatorOverrideController can only override controller for all blocks simultaneously, changing animation for all of them in the same time, but not depending on each block's behaviour.
Is there a way to have each block have own animation override timing, and can it be done with AnimatorOverrideController?
Here is what i use for this:
public AnimatorOverrideController animatorOverrideController;
public AnimationClip blockAnimation;
public AnimationClip redBlockAnimation;
void OverrideAnimatorController()
{
var animator = GetComponent<Animator>();
animator.runtimeAnimatorController = animatorOverrideController;
animatorOverrideController["BlockAnim"] = redBlockAnimation;
}
void ReturnAnimationController()
{
animatorOverrideController["BlockAnim"] = blockAnimation;
}
public IEnumerator Phasing()
{
...
yield return new WaitForSeconds(Random.Range(3,8));
OverrideAnimatorController();
yield return new WaitForSeconds(Random.Range(3, 8));
ReturnAnimationController();
}
Your answer
Follow this Question
Related Questions
Jump and fall animations not working 2 Answers
How to attach an object to another? 1 Answer
Problem with animation 0 Answers