Basically i want my Unit to have a delay when switching Targets, or when first attacking an enemy, imy implementation already has a cooldown in between attacks but i want it to have a delay as if getting ready to attack a new enemy.
void Update()
{
Collider[] inRange = Physics.OverlapSphere(transform.position, 50f);
int i = 0;
while (i < inRange.Length)
{
if (inRange_.tag != transform.tag && inRange*.tag != "LEVEL")*_
{
RaycastHit LineofSight;
if (Physics.Raycast(transform.position, inRange*.transform.position- transform.position, out LineofSight, range))*
{
if (LineofSight.transform.tag != gameObject.tag && LineofSight.transform.tag != “LEVEL” && (Vector3.Magnitude(inRange*.transform.position - transform.position) <= MinDistance))*
{
MinDistance = Vector3.Magnitude(inRange*.transform.position - transform.position);*
Target = LineofSight.transform.gameObject;
canSpotEnemy = true;
hasTarget = true;
}
}
}
i++;
}
if (hasTarget)
{
Attack(Target);
hasTarget = false;
Target = null;
MinDistance = Mathf.Infinity;
}
}
void Attack(GameObject target)
{
Health health = target.GetComponent();
if (health != null && Time.time-attackTime+attackRampup > 0 )
{
attackTime = Time.time + attackCooldown;
health.TakeDamage(attackDamage);
Debug.Log(target.name + transform.gameObject.name);
Debug.DrawRay(transform.position, target.transform.position - transform.position, Color.green);
}
}