【发布时间】:2014-12-11 23:56:29
【问题描述】:
我正在尝试让我的游戏在与道具碰撞时为玩家提供道具。通电功能正常,但是当它到达 yield WaitForSeconds 语句时,执行后什么也没有,导致玩家永远拥有通电,而不是设定的时间。为什么之后的代码没有执行,我该如何解决?
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);
}
【问题讨论】: