Can Someone please tell me what in doing wrong with this coroutine ? *pretty please*

Im trying to use the coroutine to delay an action below and then carry out the functions i have , but is does not seem to be working , im lost with this one

using UnityEngine;
using System.Collections;

public class RingScript : MonoBehaviour {

	     public bool inForceTrigger;
	     public bool inSecondForceTrigger;
	     public bool inRoofTrigger;                           
	     public bool inHookTrigger; 
	   

	IEnumerator GetOutOfCollider (float delay)
	{
	yield return new WaitForSeconds(delay);
	transform.FindChild ("Sphere").gameObject.SetActive (true);
	transform.FindChild ("Box").gameObject.SetActive (false);

	}

	void OnTriggerEnter (Collider other)
	{
	if (other.tag == "RoofCollider")
	{
	inRoofTrigger = true;
	}
	if (other.tag == "LowHookTrigger") 
	{
	inHookTrigger = true;
    }
	if (other.tag == "SecondForceCollider")
	{
	inSecondForceTrigger = true;
	}
	if (other.tag == "ForceCollider")
	{
	inForceTrigger = true;
	}
	}

	void OnTriggerExit (Collider other)
	{
	if (other.tag == "RoofCollider") 
	{
	inRoofTrigger = false;
	}
	if (other.tag == "LowHookTrigger") 
	{
	inHookTrigger = false;
	}
	if (other.tag == "SecondForceCollider")
	{
	inSecondForceTrigger = false;
	}
	if (other.tag == "ForceCollider")
	{
	inForceTrigger = false;
	}

	}



	void FixedUpdate ()
	{
	if (inRoofTrigger == false  inHookTrigger == false  inSecondForceTrigger == false  inForceTrigger == false ) 
	{
	transform.FindChild ("Box").gameObject.SetActive (false);
    transform.FindChild ("Sphere").gameObject.SetActive (true);
	rigidbody.constraints = RigidbodyConstraints.None;
    rigidbody.collisionDetectionMode = CollisionDetectionMode.Discrete;
	} 
	if (inRoofTrigger == true)
	{
	rigidbody.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic;
    } 
	if (inRoofTrigger == true  transform.FindChild("Box").GetComponent<BoxScript>().boxInHookTrigger == false )
	{
	StartCoroutine(GetOutOfCollider(10.0f));
	}
	if (inHookTrigger == true )
	{
	transform.FindChild ("Box").gameObject.SetActive (true);
	transform.FindChild ("Sphere").gameObject.SetActive (false);
	rigidbody.constraints = RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionZ;
    rigidbody.AddForce (1, -2,0);
	}
	if (inSecondForceTrigger == true)
	{
	rigidbody.AddForce (6, 0,0);
	}
	if ( GameObject.FindWithTag("Level01GUI").GetComponent<GUIScript>().buttonPress  inForceTrigger == true ) 
	{
	rigidbody.AddForce (200, 900,0);
	}

	}
}

HI Dub,

First, for more clarity with your script, I would recommend that you indent your lines when it is necessary.

For Example:

using UnityEngine;
using System.Collections;

public class RingScript : MonoBehaviour {

     public bool inForceTrigger;
     public bool inSecondForceTrigger;
     public bool inRoofTrigger;                          
     public bool inHookTrigger;   

     // add your comments here to explain what you want to do
     IEnumerator GetOutOfCollider (float delay){
          yield return new WaitForSeconds(delay);
          transform.FindChild ("Sphere").gameObject.SetActive (true);
          transform.FindChild ("Box").gameObject.SetActive (false);
     }

It is much easier to read a script when it is well formatted.

Then to answer your question :slight_smile: did you try to add some debug lines?
You should put that line just where you would like to see if this is playing (so for example inside the coroutine)

Debug.Log("enter comment here");

Also, are you sure the section below triggers?

    if (inRoofTrigger == true  transform.FindChild("Box").GetComponent<BoxScript>().boxInHookTrigger == false ){
         StartCoroutine(GetOutOfCollider(10.0f));
    }

If it doesn’t then, you probably should check if your bools meet your requirement :).
You can add a debug line with the bool inside like this :

     Debug.Log("Bool : " + inRoofTrigger + " " + transform.FindChild("Box").GetComponent<BoxScript>().boxInHookTrigger);

Also on another note, if you are only using one “Box”, you should probably store your variable, so you don’t call it every Updates. (GetComponent can be expensive).

Hi Laurel , thanks very much , bit of an air head here (maybe sitting at this for to long without a break ) . Turns out after using your debug line the script was working just fine , i changed the functions to just Destroy (gameobject) ; and put the timer to 1.0f and it destroyed the game objects as I wanted . Need to take a break lol but thanks a lot for that

(there is 10 Box child objects in the scene so, I tried storing as a variable and using a which box am I string method but I couldn`t get what I was looking for from it there was a delay in functions that was not intentional )

Glad I could help :slight_smile:
Good luck in your project!