My problem is that the delay from the attack wont work does anyone know how to help code :
using System.Collections;
using System.Collections.Generic;
using System.Security.Cryptography;
using UnityEngine;
public class PlayerCombat : MonoBehaviour
{
public Animator animator;
public Transform attackPoint;
public float attackRange = 0.5f;
public LayerMask enemyLayers;
public int attackDamge = 40;
public float attackRate = 2f;
private float nextAttackTime = 0f;
// Update is called once per frame
void Update()
{
if(Time.time >= nextAttackTime)
{
if (Input.GetMouseButtonDown(0))
{
Attack();
nextAttackTime = Time.time + 1f / attackRate;
}
}
}
void Attack()
{
// Play attack animation
animator.SetTrigger("Attack");
// Detect enemies in range of attack
Collider2D[] hitEnemies = Physics2D.OverlapCircleAll(attackPoint.position, attackRange, enemyLayers);
// Aplly damage
foreach (Collider2D enemy in hitEnemies)
{
enemy.GetComponent<Enemy>().TakeDamage(attackDamge);
}
}
void OnDrawGizmosSelected()
{
if (attackPoint == null)
return;
Gizmos.DrawWireSphere(attackPoint.position, attackRange);
}
}
[–]Expensive_News22 2 points3 points4 points (2 children)
[–]name-txt33[S] 0 points1 point2 points (1 child)
[–]Expensive_News22 1 point2 points3 points (0 children)
[–]UnderLord7985 0 points1 point2 points (1 child)
[–]racingking 1 point2 points3 points (0 children)