Home>

I want to switch to another character when I press the button

http://miyas-maincontents.blogspot.com/2016/03/blog-post_23.html
I made and implemented almost the same as the source code of the above site. As a result, I was able to switch characters, but there was no animation. Strictly speaking, the very first character has an animation, but the character to switch to did not. Why is the animation attached to the parent object reflected in the child object in the first place?

using System.Collections;
using UnityEngine;
public class CharacterChange: MonoBehaviour
{
    public Avatar [] avatars = new Avatar [2];
    public GameObject [] characters = new GameObject [2];
    private int index = 0;
    private Animator player Animator;

    // Start is called before the first frame update
    void Start ()
    {
        playerAnimator = GetComponent  ();
    }
    // Update is called once per frame
    void Update ()
    {
        Change ();
    }
    void Change ()
    {
        if (Input.GetKeyDown (KeyCode.X))
        {
            index ++;
            if (index == 2) index = 0;
            foreach (GameObject gamObj in characters)
            {
                gamObj.SetActive (false);
            }
            characters [index] .SetActive (true);
            playerAnimator.avatar = avatars [index];
        }
    }
}
What I tried

I wondered if I could switch the animation from the program, so I added the following program, but nothing changed. What should i do? Please let me know.

public class CharacterChange: MonoBehaviour
{
    public Avatar [] avatars = new Avatar [2];
    public GameObject [] characters = new GameObject [2];
    private int index = 0;
    private Animator player Animator;
    //add to
Public RuntimeAnimatorController [] animators = new RuntimeAnimatorController [2];
 void Change ()
    {
        if (Input.GetKeyDown (KeyCode.X))
        {
            index ++;
            if (index == 2) index = 0;
            foreach (GameObject gamObj in characters)
            {
                gamObj.SetActive (false);
            }
            characters [index] .SetActive (true);
            playerAnimator.avatar = avatars [index];
            //add to
PlayerAnimator.runtimeAnimatorController = animators [index];
        }
    }
}
Supplementary information (FW/tool version, etc.)

The version of Unity is 2019.4.3f1.
Please let me know if there is any missing information.