using UnityEngine;
using System.Collections;
public class TurretShells : MonoBehaviour
{
public GameObject turretEmitter;
public GameObject shell;
public float shellForce;
void OnTriggerEnter(Collider CharacterController)
{
while (true)
{
StartCoroutine(haltTime());
GameObject Temporary_Bullet_Handler;
Temporary_Bullet_Handler = Instantiate(shell, turretEmitter.transform.position, turretEmitter.transform.rotation) as GameObject;
Rigidbody Temporary_RigidBody;
Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent<Rigidbody>();
Temporary_RigidBody.AddForce(transform.forward * shellForce);
Destroy(Temporary_Bullet_Handler, 3.0f);
}
}
IEnumerator haltTime()
{
yield return new WaitForSeconds(2);
}
}
My goal is to get the while loop under “void OnTriggerEnter” to contain the WaitForSeconds function; I want it to execute “haltTime” through every pass of the loop to avoid an emitter from causing the application to freeze because of an overload of created prefabs. I have the “yield return new WaitForSeconds(2);” section set properly, but the “StartCoroutine(haltTime());” line is not having any effect on the application. If someone could help me set the WaitForSeconds coroutine starter to work in the while loop, that would be great.