unity c# change animator controller 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");
    }
}