I’m trying to make a script where when a powerup hits the player, he receives the powerup for X amount of seconds. It is working except nothing after the WaitForSeconds statement is executing. This results in him having the powerup forever. ( Debug.Log(“Finished waiting”) and deactivatePowerup( player) are never called…
public void OnCollisionEnter2D( Collision2D collision ){
if (collision.gameObject.tag == "Player") {
if(isActive){
isActive = false;
gameObject.renderer.enabled = false;
StartCoroutine( activatePowerup( collision.gameObject ) );
}else;
Debug.Log ("Hit player");
}else if (collision.gameObject.tag == "Ground") {
Destroy(gameObject);
}
}
public IEnumerator activatePowerup( GameObject player ){
player.GetComponent<Player>().setAttackDelaySeconds (0.25f);
Debug.Log ("Powerup Activated");
yield return new WaitForSeconds(2.0f);
Debug.Log ("Finisehd waiting");
deactivatePowerup ( player );
}
public void deactivatePowerup( GameObject player ){
player.GetComponent<Player> ().setAttackDelaySeconds (0.75f);
Debug.Log ("Powerup Finished");
Destroy (gameObject);
}