How i can make each mouse click will display diffrenet combo animation

hello How i can make each mouse click will display diffrenet combo animation ? and cancel holding the mouse button

Not going to be super useful, but you code what you want to be done.

Something like onKeyDown rotate through what you want to display. OnKeyUp cancel what you’re currently displaying.

Without specifics, it’s tough to offer you more than a general idea of the logic behind it.

The last part is the trickiest, I’d probably use a right click to cancel… It’s easier to set an event up for that and subscribe to it.

For the mouse click to cycle through a group of attacks, we’ll need to set up some events:

In InputHandler, we’ll need a

public event AttackDownEvent;

and in the Attack event block, in the IsPerformed section, we’ll need to add

AttackDownEvent?.Invoke();

Next, in PlayerAttackingState, we’ll need a couple of values…

int nextAttack;
int maxAttacks;

Set nextAttack to the current attack’s ComboStateIndex in Enter.

We’ll also need to subscribe to the InputHandler’s AttackDownEvent.

Next, we’ll need an event to invoke our UI… This one’s a bit tricky, but as we’re doing an event driven approach, we’ll need to deal with the concept of a callback.

public event System.Action<int, int, System.Action<int>> OnAttackPerformed;

This event will be used in our UI whenever we click the mouse button after the attack has started.
Our handler for the AttackDownEvent in the PlayerAttackingState will work like this:

    void HandleAttackDown()
    {
        OnAttackPerformed?.Invoke(nextAttack, maxAttacks, (int i) => nextAttack = i);
    }

The first number is the nextAttack value, the 2nd the max number of attacks, and the last bit is a closure which sets the value of NextAttack to the value passed into the callback.

In our UI, we’ll need a method with this signature:

void OnAttackPerformed(int nextAttack, int maxAttacks, System.Action<int> callback)
{
    nextAttack++;
    nextAttack = nextAttack % maxAttacks;
    //update your UI here
    callback?.Invoke(nextAttack);
}

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

Privacy & Terms