attack speed of the character

hi guys. i am currently having a problem in the attack speed of my character. All i want is that i can control the speed of shooting when my character meets an enemy in the path but my character is attacking simultaneously without any delay such as 1 attack per 2 second and so on…

This is my code and this is triggered once an enemy is in the range of my character.

Quaternion targetRotation = Quaternion.LookRotation(goal - transform.position);
transform.rotation = targetRotation;

		Transform bullet = Instantiate(baloon,spawnPoint.transform.position, transform.rotation) as Transform;
		bullet.rigidbody.AddForce(transform.forward*50,ForceMode.VelocityChange);

can you please help me??i am new in unity by the way.

you can create an if statement, that checks how much time has elapsed since the last attack.

It would look kinda like this:

public float AttackInterval = 3; //1 attack every 3rd second
private float elapsedTime = 0;

//whenever the character is attacking...
if(Time.time > elapsedTime)
{
     Transform bullet = Instantiate(baloon,spawnPoint.transform.position, transform.rotation) as Transform;
    bullet.rigidbody.AddForce(transform.forward*50,ForceMode.VelocityChange);
     elapsedTime = Time.time + AttackInterval
}

You can use (yield WaitForSeconds()) in your script
Simply like this:

void Play(){
animation.play(“AnimName”);
yield WaitForSeconds (5);//wait for 5 sec
}
(-: