Hello everyone,
I'm trying to make a bonus that starts with a trigger and last for one second. I've made a coroutine for that. here's my simplified code.
Here's what I get in the console :
About to StartCoroutine
disable
about to yield return WaitForSeconds(1)
back from StartCoroutine
And never get the "Just waited 1 second" log, as long as I have the ligne renderer.enabled = false or gameObject.SetActive(false). When I remove that line everyhting works perfectly... But I still need to hide the gameObjectand disable it's collider.
void OnTriggerEnter2D ()
{
activated = true;
Debug.Log ("About to StartCoroutine");
StartCoroutine (MyCoroutine ());
Debug.Log ("Back from StartCoroutine");
}
IEnumerator MyCoroutine ()
{
this.Disable ();
Debug.Log ("about to yield return WaitForSeconds(1)");
yield return new WaitForSeconds (1);
Debug.Log ("Just waited 1 second");
}
void Disable ()
{
Debug.Log ("disable");
this.collider2D.enabled = false;
this.renderer.enabled = false;
//gameObject.SetActive (false);
}
Do you have any idea ?
↧