I have a coroutine that runs on a collision, coded like so within a script ‘A’
void OnTriggerEnter (Collider col)
{
if (col.collider.tag == "Impulse")
{
impOpticARenderer.renderer.enabled = false;
impOpticBRenderer.renderer.enabled = false;
diencephalonRRenderer.renderer.material = glow;
StartCoroutine(SequentialRenderers());
}
}
public IEnumerator SequentialRenderers()
{
yield return new WaitForSeconds (waitTime1);
hemibrainRightRenderer.renderer.material = glow;
yield return new WaitForSeconds(waitTime2);
cerebellumLeftRenderer.renderer.material = glow;
yield return new WaitForSeconds(waitTime3);
myencephalonLeftRenderer.renderer.material = glow;
impFacialARenderer.renderer.enabled = true;
impFacialBRenderer.renderer.enabled = true;
impFacial.passedTime = 0f;
impFacial.speed = 0.2f;
On a separate script ‘B’ I’d now like to access and stop/ reset this coroutine in script A so it’s ready for the next collision, when you hit the spacebar. I’ve so far been unsuccessful. I’ve tried making the coroutine a public method, and writing
void Update () {
if (Input.GetKey(KeyCode.Space))
{
StopCoroutine(SequentialRenderer());
impOpticARenderer.renderer.enabled = true;
impOpticBRenderer.renderer.enabled = true;
impOptic.speed = 0.8f;
impOptic.passedTime = 0;
}
I have a feeling this wouldnt work anyway, as it won’t actually reset the initial coroutine, just pause it. Can anyone offer some advice?
Thanks in advance