public List <Powerup> powerupsWithinRange = new List <Powerup>(); //This list will hold all powerups that are within the players detection range collider. private void Update() { if (Input.GetKey(KeyCode.C) && _isWithinRange) { _outOfRange = false; _isAttractingPowerup = true; if (powerup != null) { foreach (Powerup powerup in powerupsWithinRange) { powerup.AttractPowerup(); } } } if (Input.GetKeyUp(KeyCode.C) && _isAttractingPowerup && !_outOfRange || !_outOfRange && !_isWithinRange) { _isAttractingPowerup = false; _outOfRange = true; if (powerup != null) { powerup.StopAttractingPowerup(); } } }