Creating delay inside event

I want a delay between attacks, and a series of 3 attacks per event. However, I can’t seem to get the delay I want.

public void pew()
{
delay = -1;
int thrice = 0;
do {
if (delay < 0 )
{
Vector3 position = transform.position;
double choice = Random.Range (-10, 10);
if (choice > 0) {
Instantiate (knife, position, transform.rotation);
delay =20000000;
} else {
position.y -= 1.7f;

Instantiate (knife, position, transform.rotation);
delay =20000000;
}

thrice += 1;
}
delay -=1;
} while (thrice < 3);

}

Code tags please.

As it is your code looks like a mess. Why not use a coroutine and a for loop?

2 Likes

OK : ) sorry, I"m pretty knew to coding, I should probably google things before posting to the forums…didn’t even know coroutine existed. It’s working now though.

2 Likes

That’s what I would do.

Sweet. Good luck!