- Home /
Question by
Natfran · Jul 08, 2017 at 06:39 AM ·
animatorruntimeanimator controllerswitch
How to switch Animator controllers in script?
So basically I am trying to switch animator controllers for my player because it has a melee attack and a range attack. The melee attack and range attack have different animations. But the code in my script doesn't seem to work.
This is the code:
if (UseSword == true) {
Sword.SetActive (true);
animator.runtimeAnimatorController = Resources.Load ("Assets/SpaceMan") as RuntimeAnimatorController;
Gun.SetActive (false);
Comment
Answer by Vollmondum · Jul 08, 2017 at 07:57 AM
var ranged: boolean;
var myControllers: RuntimeAnimatorController[];
var animator: Animator;
function Update()
{
if(!ranged)
{
animator = myControllers[0];
}
if(ranged)
{
animator = myControllers[1];
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612125756im_/https://answers.unity.com/themes/thub/images/avi.jpg)