Animator playerAnimator = GetComponent(); AnimationClip jumpAnimation = Resources.Load ("Jump"); playerAnimator.runtimeAnimatorController = Resources.Load ("PlayerController"); playerAnimator.AddAnimation("Jumping", jumpAnimation, 0.5f, 0.0f, true);
Animator enemyAnimator = gameObject.GetComponentIn this example, the AddAnimation method is used to add an attack animation to an enemy character in the game. The animation clip is loaded from a resource called "Attack", and the duration of the animation is set to 0.8 seconds. The animation will only play once and will not loop. The Animator AddAnimation method is part of the Unity Engine package library.(); AnimationClip attackAnimation = Resources.Load ("Attack"); enemyAnimator.runtimeAnimatorController = Resources.Load ("EnemyController"); enemyAnimator.AddAnimation("Attacking", attackAnimation, 0.8f, 0.0f, false);