Smaika
Smaika

Reputation: 1237

Change Animator Controller by Script

I have 2 Controllers may

1-ControllerBLUE.controller (Default)

2-ControllerRED.controller

How can I change the controller from script

I tried:

var colorController = GetComponent(Animator);


 colorController.runtimeAnimatorController =   Resources.Load("main/colors/controllercolors/ControllerRED.controller ") as RuntimeAnimatorController;

But it doesn't work it just make the animator controller to : "None (Runtime Animator Controller)"

Is it possible ? How can I make it work ?

Upvotes: 3

Views: 19509

Answers (1)

Giulio Pierucci
Giulio Pierucci

Reputation: 121

I'm sorry, I use C# in Unity:

using UnityEngine;
using System.Collections;
public class ChangeController : MonoBehaviour {

Animator animator;

// Use this for initialization
void Start () {
    animator = gameObject.GetComponent<Animator>();
    animator.runtimeAnimatorController = Resources.Load("main/colors/controllercolors/ControllerRED") as RuntimeAnimatorController;
}

// Update is called once per frame
void Update () {

} }

Upvotes: 6

Related Questions