如何在运行时向角色添加动画控制器?

Ash*_*vis 2 animation unity-game-engine

我在“Assets/Resources/System/PLController”中有一个 Animator 控制器。我必须在运行时使用脚本添加它。如何实现这一点。使用Unity 5 (5.3.0f4)

PLController =(动画控制器)

Ham*_*san 5

首先将一个Animator组件附加到GameObject上面

动画组件

  • 声明一个Animator变量。

  • 通过分配变量GetComponent

  • 分配RuntimeAnimatorController给它的runtimeAnimatorController属性。

喜欢,

Animator PLAnimator;

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