Hi, I want to put a cooldown after my character does a complete combo. I mean, after it does the last combo, the character should stop attacking by player comand for a while. I am using triggers for attack combos, and put a script in the StateMachine for this.
Here is the script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class combo_knight : StateMachineBehaviour
{
public int attackId = 1;
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
if (Input.GetButtonDown("Attack"))
{
animator.SetTrigger("attack" + attackId);
}
}
}
This is the script for player movement:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class knight_movement : MonoBehaviour
{
[SerializeField] private Rigidbody _rb;
[SerializeField] private float _speed = 6;
private Vector3 _input;
private Animator animator;
private bool canMove = true;
private bool canAttack = true;
private float combo;
public float cooldown;
void Start()
{
animator = GetComponentInChildren<Animator>();
}
void Update()
{
GatherInput();
Look();
if(combo >= 4)
{
canAttack = false;
}
}
void FixedUpdate()
{
Move();
if (canAttack == true && cooldown == 0 && combo < 4)
{
if (Input.GetButtonDown("Attack"))
{
combo++;
combo += 1;
}
}
}
void GatherInput()
{
_input = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
}
void Look()
{
if (_input != Vector3.zero)
{
transform.forward = _input;
}
}
void Move()
{
if (canMove == true)
{
_rb.MovePosition(transform.position + (transform.forward * _input.magnitude) * _speed * Time.deltaTime);
if (_input != Vector3.zero)
{
animator.SetBool("movement", true);
}
else
{
animator.SetBool("movement", false);
}
}
}
public void Attacking()
{
canMove = false;
}
public void StopAttacking()
{
canMove = true;
}
}
Attacking and StopAttacking are used in the animation events: they are supposed to stop the player moving, when attacking.
Can you help me?