void RemoveExpiredPowerups() { for (int i = powerups.Count - 1; i >= 0; i--) { Powerup powerup = powerups[i]; if (powerup.IsExpired()) { powerups.RemoveAt(i); } } }
// Update is called once per frame void Update() { //Store the current horizontal input in the float moveHorizontal. float moveHorizontal = Input.GetAxis("Horizontal"); //Store the current vertical input in the float moveVertical. float moveVertical = Input.GetAxis("Vertical"); Movement(moveHorizontal, moveVertical); // Prevent double jumping if (Input.GetKeyDown("space") && (midJump == false)) { Jump(); midJump = true; } if (GetComponent <Rigidbody2D>().velocity.y == 0) { midJump = false; } if (hasPowerup) { if (playerPowerup.IsExpired()) { Debug.Log("Powerup has expired"); hasPowerup = false; if (playerPowerup.type == Modifier.INVINCIBLE) { isInvincible = false; } else if (playerPowerup.type == Modifier.JUMPHEIGHT) { isDoubleJump = false; } else if (playerPowerup.type == Modifier.SPEED) { isFast = false; } } } // start recovery counter TimeSpan notime = new TimeSpan(0); DateTime now = DateTime.Now; if (isRecovering) { if (sec.Subtract(now).CompareTo(notime) <= 0) { if (gameObject.GetComponent <SpriteRenderer>().enabled) { gameObject.GetComponent <SpriteRenderer>().enabled = false; sec = DateTime.Now.AddSeconds(flickerLength); } else { gameObject.GetComponent <SpriteRenderer>().enabled = true; sec = DateTime.Now.AddSeconds(flickerLength); } } if (time.Subtract(now).CompareTo(notime) <= 0) { gameObject.GetComponent <SpriteRenderer>().enabled = true; isRecovering = false; } if (!isInvincible && health <= 0) { KillPlayer(); } } }