EnemyAI - Random Attack

I am very new to unity and c#. I just finished enemyAI in Unity 3rdPersonCombat & Traversal recently. I tried several times without success. I would like to know if there is an easy way to realize that monsters use random attacks in scripts instead of a single attack?

Fortunately, we’ve already set things up for this with our Combo attacks in the Player…
Much like the Player, you’re going to need an array of Attacks on the EnemyStateMachine, with corresponding attack names (states in the Animator), etc.

In the EnemyAttackState.Enter(), select a random Attack from the EnemyStateMachine’s Attacks array

Attack attack = stateMachine.Attacks[Random.Range(0, stateMachine.Attacks.Length)];

This is the attack you’ll use for that current EnemyAttackState. The next time EnemyAttackState is created, another random attack will be selected.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms