StartCoroutine, yield return new WaitForSeconds(3.0f); // not working

OnTriggerEnter coroutine starts but message after yield return new WaitForSeconds(5); is not working >>

The guy is runnning and OnTrigger enter i wish to start the coroutine, and till the time this coroutine lasts, guy has some power,

but yield return new WaitForSeconds(3.0f); is not working, why this strange behaviour from unity ??

using UnityEngine;
using System.Collections;

public class powerup1 : MonoBehaviour {
	
	public static bool powerup1ON;
	public int powerup_status;

	// Use this for initialization
	void Start () {
	transform.Rotate(90, 180, 0);
		powerups.Load_powerup_1_status();
			}
	
	// Update is called once per frame
	void Update () {
	
	}
	
		IEnumerator Tcounter5sec (){
		Debug.Log("inside counter");
yield return new WaitForSeconds(3.0f);
Debug.Log("3 secs");
powerup1ON=false;		
}
	
	void OnTriggerEnter(Collider other) {
		if(other.gameObject.tag == "Player"){
			
			powerup1ON=true;
			powerup_status = powerups.p1stat;
			Debug.Log("Power Up 1="+powerup_status);
			StartCoroutine(Tcounter5sec());
			
			//Destroy(gameObject);
    }}
	
	 void OnBecameInvisible() {
		//Debug.Log("Invisible Obstacle");
        Destroy(gameObject);
    }
	

	
}

Is line21 calling?
I would put a line after your call to start the coroutine. See if that prints.

Found the problem

i disabled this line
Destroy(gameObject);

and it is working, may be the object gets destroyed and due to which problem occured

Most likely. Good work Sherlock! Detective work is key in programming. Yeh.

:slight_smile: