void TickPowerups() { // remove all elapsed powerups activePowerupList.RemoveAll((p) => { return(p.ElapsedTime > p.MaxTime); }); // zero out powerups before we add them all up var powerups = new Stats(); // add up all our powerups for (int i = 0; i < activePowerupList.Count; i++) { var p = activePowerupList[i]; // add elapsed time p.ElapsedTime += Time.deltaTime; // add up the powerups powerups += p.modifiers; } // add powerups to our final stats finalStats = baseStats + powerups; // clamp values in finalstats finalStats.Grip = Mathf.Clamp(finalStats.Grip, 0, 1); finalStats.Suspension = Mathf.Clamp(finalStats.Suspension, 0, 1); }
void TickPowerups() { //Set player control every tick hasControl = true; //Remove jump effect every tick shouldBeJump = false; // remove all elapsed powerups activePowerupList.RemoveAll((p) => { return(p.ElapsedTime > p.MaxTime); }); // zero out powerups before we add them all up var statsPoweups = new Stats(); // add up all our powerups for (int i = 0; i < activePowerupList.Count; i++) { var p = activePowerupList[i]; // add elapsed time p.ElapsedTime += Time.deltaTime; // add up the powerups if (p is StatPowerUp) { statsPoweups += (p as StatPowerUp).modifiers; } //Disable movement if player no has control if (p is LoseControl) { hasControl = false; } if (p is Jump) { shouldBeJump = true; } } if (!hasControl) { statsPoweups.TopSpeed = 5; statsPoweups.Steer = baseStats.Steer * 2; } // add powerups to our final stats finalStats = baseStats + statsPoweups; // clamp values in finalstats finalStats.Grip = Mathf.Clamp(finalStats.Grip, 0, 1); finalStats.Suspension = Mathf.Clamp(finalStats.Suspension, 0, 1); }