问题
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
Animatorvariable.Assign variable through
GetComponentAssign
RuntimeAnimatorControllerto itsruntimeAnimatorControllerattribute.
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