79572785

Date: 2025-04-14 09:30:07
Score: 1
Natty:
Report link

I did it using Animator Override Controller

private AnimatorOverrideController overrideController;

    private void Awake()
    {
        overrideController = new AnimatorOverrideController(animator.runtimeAnimatorController);
        animator.runtimeAnimatorController = overrideController;
    }

    public void PlayerBaseAttack()
    {
        if (currentAttackType != null)
        {
            var pair = attackAnimationList.Find(p => p.attackType == currentAttackType);
    
            if (pair != null && pair.animations.Length > 0)
            {
                AnimationClip chosenClip = pair.animations[Random.Range(0, pair.animations.Length)];
    
                overrideController["Attack"] = chosenClip;
                animator.SetTrigger("Attack");
            }
        }
    }
Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Ilya