I’m having trouble with my enemy AI firing rapid fire at my player when they should be delaying after each shot. I have tried start Coroutines and yields but nothing slows down the firing.
This is the code I’m trying to work with:
//IEnumerator Fire()
void Fire ()
{
// yield return StartCoroutine(MyWaitFunction (1.0f));
inputMovement = objPlayer.transform.position - transform.position;
inputRotation = inputMovement; // face the direction we are moving, towards the player
tempVector = Quaternion.AngleAxis(8f, Vector3.up) * inputRotation;
tempVector = (transform.position + (tempVector.normalized * 0.8f));
GameObject objCreatedBullet = (GameObject) Instantiate(ptrScriptVariable.objBullet, tempVector, Quaternion.LookRotation(inputRotation) ); // create a bullet, and rotate it based on the vector inputRotation
Physics.IgnoreCollision(objCreatedBullet.collider, collider);
}
/*
IEnumerator MyWaitFunction (float delay) {
float timer = Time.time + delay;
while (Time.time < timer) {
yield return;
}
}
*/
I’ve included comments of different things I’ve tried.[/code]