yield WaitForSeconds

Hello eveyone, is there any way to do if statement with yield WaitForSeconds? Like,

if(yield WaitForSeconds(5)){
  //do stuff here
}

I tried but it doesn’t work. Any suggestions?

Thanks :slight_smile:

You should just remember the amount of potions in the inventory before the wait and check if it’s the same afterwards. Now, if there are other, allowed, ways of getting potions you will have to update my numberOfPotions accordingly, because this script doesn’t discriminate.

Basic idea:

	function OnTriggerEnter (col : Collider){
				
	    if(col.gameObject.tag=="Player"){
			int numberOfPotions = Invetory.inventoryArray[0];
	    	yield WaitForSeconds(1f);
			if(Invetory.inventoryArray[0] > numberOfPotions){
				//Player has cheated... possibly. 
				Invetory.inventoryArray[0] = numberOfPotions;
			}else{
			    Invetory.inventoryArray[0]++;
			    Destroy(gameObject);
			}
			
    	}
    }