How to add a Animator Controller to a character at runtime?

若如初见. 提交于 2019-12-12 04:18:54

问题


I have an Animator controller at "Assets/Resources/System/PLController". I have to add it at runtime using a script. How to accomplish this. Using Unity 5 (5.3.0f4)

PLController = (Animator Controller)


回答1:


First attach an Animator component to that GameObject like

  • Declare an Animator variable.

  • Assign variable through GetComponent

  • Assign RuntimeAnimatorController to its runtimeAnimatorController attribute.

Like,

Animator PLAnimator;

void Start ()
    {
        PLAnimator = GetComponent<Animator> ();
        PLAnimator.runtimeAnimatorController = Resources.Load ("Assets/Resources/System/PLController") as RuntimeAnimatorController;
}


来源:https://stackoverflow.com/questions/34554153/how-to-add-a-animator-controller-to-a-character-at-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!