The question is answered.
WaitForSeconds For Entering Trigger
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);
}
}
So what I am trying to do here is have a large cube trigger in front of a turret that activates upon the CharacterController game object entering that trigger. This script is only for getting the shells of the turret to fall out of the barrel. For the actual projectiles, I will be using a Raycast, but that is not what this question is focused on. I know for a fact that the trigger works and starts the process in the script, but the game always freezes from the great number of shells flying out of the barrel (possibly every frame). I decided to implement IEnumerator to add a WaitForSeconds time sleep for the while true while loop found in the script. The problem is that the StartCoroutine(haltTime()); line to execute the IEnumerator method found at the bottom of the script is not taking effect. The game acts the same way as it did without the StartCoroutine line. If I can have any way to adding a very short delay to the while loop, that would make it much better since the shells are automatically deleted after 3 seconds, so overload is not an issue if I can get the shells to come out of the emitter at a slower rate. Thank you.