Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 459
user3182651 Avatar asked Dec 06 '25 17:12

user3182651


1 Answers

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 () {

} }
like image 144
Giulio Pierucci Avatar answered Dec 09 '25 03:12

Giulio Pierucci



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!