How To Change Animator Controller In Unity Code Example


Example: how to change animator controller in script unity


//STEP1: Inside the Assets folder, create a new folder called: Resources 
//STEP2: Now Create an Animation folder Inside the Resources folder
//STEP3: Then put the Animator Controller inside this folder (for this examle we'll call the controller Bob)
//STEP4: Now add this to the gamObject that holds the Animator componentAnimator animator;

void Start()
{
animator = gameObject.GetComponent<Animator>();
}

void Update()
{
//I put it inside this If Statement to avoid Errors/Warnings but its not 100% necessary
if(animator.gameObject.activeSelf)
{
animator.runtimeAnimatorController = Resources.Load("Animation/Bob") as RuntimeAnimatorController;
//OR
animator.runtimeAnimatorController = Resources.Load<RuntimeAnimatorController>("Animation/Bob");
}
}

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable