Hello guys, I’ve been thinking about how I can do a special attack. I want to do that when I press the letter E it does a lot of punches and stops after a while, for example it does a barrage of punches and then stops after 3 seconds, I already have the code for the combat system (i just follow a tutorial from Youtube:
) and i was wondering if someone can help me to make it.
public Transform AttackPoint;
public float attackRange = 0.5f;
public LayerMask enemyLayer;
public int attackDamage = 40;
public float attackRate = 2f;
float nextAttackTime = 0f;
// Update is called once per frame
void Update()
{
//m1's
if(Time.time >= nextAttackTime)
{
if (Input.GetButtonDown("Fire1"))
{
attack();
nextAttackTime= Time.time + 1f / attackRate;
}
}
//Barrage
if (Input.GetKey(KeyCode.E))
{
}
}
void attack()
{
//Detect enemies in the range of attack
Collider2D[] hitEnemy = Physics2D.OverlapCircleAll(AttackPoint.position, attackRange, enemyLayer);
//Damage enemy
foreach(Collider2D enemy in hitEnemy)
{
enemy.GetComponent<Dummy>().TakeDamage(attackDamage);
}
}
private void OnDrawGizmos()
{
if(AttackPoint == null)
{ return; }
Gizmos.DrawWireSphere(AttackPoint.position, attackRange);
}
}
also i apologize for my grammar.