/* * // Update is called once per frame * void Update() * { * //updateUIText(); * } * * public void updateUIText() * { * //rpm = getUpdatedStats.CalculateRPM(); * rpm = WorkoutCalculations.CalculateRPM(); * rpmText.text = rpm.ToString(); * * //speed = getUpdatedStats.CalculateSpeed(); * speed = WorkoutCalculations.CalculateSpeed(Bike.Instance.RPM); * speedText.text = speed.ToString(); * * //resistance = getUpdatedStats.CalculateResistance(); * resistance = WorkoutCalculations.CalculateResistance(); * resistanceText.text = resistance.ToString(); * * //watts = getUpdatedStats.CalculatePowerOutput(); * watts = WorkoutCalculations.CalculatePowerOutput(Bike.Instance.RPM); * wattsText.text = watts.ToString(); * * //distance = getUpdatedStats.CalculateDistance(); * distance = WorkoutCalculations.CalculateDistance(Bike.Instance.Count); * distanceText.text = distance.ToString("F2"); * * // Need to be event for this one * //calories += getUpdatedStats.CalculateCalories(); * caloriesText.text = "TBD"; //calories.ToString(); * } */ IEnumerator UpdateUiStats() { while (true) { rpm = WorkoutCalculations.CalculateRPM(); rpmText.text = rpm.ToString(); speed = WorkoutCalculations.CalculateSpeed(Bike.Instance.RPM); speedText.text = speed.ToString("F2"); resistance = WorkoutCalculations.CalculateResistance(); resistanceText.text = resistance.ToString(); watts = WorkoutCalculations.CalculatePowerOutput(Bike.Instance.RPM); wattsText.text = watts.ToString(); if (rpm != 0) { distance = WorkoutCalculations.CalculateDistance(Bike.Instance.Count); distanceText.text = distance.ToString("F2"); calories += WorkoutCalculations.CalculateCalories(); caloriesText.text = calories.ToString(); } yield return(new WaitForSeconds(1)); } }
// Tracks the speed every second IEnumerator MaintainSpeedTracker(MaintainSpeed challenge, float time) { // Loops and calculate the time that has passed for (float deltaTime = 0; ; deltaTime = Time.time - time) { // Calculate the current speed float speed = WorkoutCalculations.CalculateSpeed(Bike.Instance.RPM); // Check if the speed is correct and the time is achieved if (deltaTime >= challenge.Time && speed >= challenge.Speed) { StartCoroutine(MaintainSpeedTrigger(challenge)); yield break; } else if (speed >= challenge.Speed) { // speed is correct, time is not achieved, wait for a second and check again yield return(new WaitForSeconds(1)); } else { // Resets the challenges as the player failed challenge.Active = false; yield break; } } }
// Updates the livestats of the leaderboard private void UpdateLiveStatsMainThread(StatsUpdateEventArgs e) { players[e.peerId].distance = WorkoutCalculations.CalculateDistance(e.rotations); //BLEDebug.LogInfo($"STAT: {e.peerId} {players[e.peerId]} {e.rotations}"); if (racing && e.peerId >= 1 && e.peerId <= 8 && isActive == true) { lbTemplate[players[e.peerId].rank - 1].Find("Place").GetComponent <Text>().text = players[e.peerId].rank.ToString(); lbTemplate[players[e.peerId].rank - 1].Find("Distance").GetComponent <Text>().text = players[e.peerId].distance.ToString("F2"); hsTemplate[players[e.peerId].rank - 1].Find("Place").GetComponent <Text>().text = players[e.peerId].rank.ToString(); hsTemplate[players[e.peerId].rank - 1].Find("Distance").GetComponent <Text>().text = players[e.peerId].distance.ToString("F2"); } }
private void Update() { // Checks if the top speed is correct if (PlayerPrefs.GetInt("TopSpeed1") != 1 && WorkoutCalculations.CalculateSpeed(Bike.Instance.RPM) >= challenges.tsc01.Speed) { StartCoroutine(TopSpeedTrigger(challenges.tsc01)); } // Checks if the speed is above a certain amount if (PlayerPrefs.GetInt("MaintainSpeed1") != 1 && challenges.msc01.Active == false && WorkoutCalculations.CalculateSpeed(Bike.Instance.RPM) >= challenges.msc01.Speed) { float startTime = Time.time; challenges.msc01.Active = true; StartCoroutine(MaintainSpeedTracker(challenges.msc01, startTime)); } // Checks if a certain amount of distance is achieved if (PlayerPrefs.GetInt("TotalDistance1") != 1 && WorkoutCalculations.CalculateDistance(Bike.Instance.Count) >= challenges.tdc01.Distance) { StartCoroutine(TotalDistanceTrigger(challenges.tdc01)); } }
private void Update() { // MAY NEED TO CHECK IF MATCH IS FINISHED FIRST // Checks if the top speed is correct if (tsc01.Achieved == false && WorkoutCalculations.CalculateSpeed(Bike.Instance.RPM) >= tsc01.Speed) { StartCoroutine(TopSpeedTrigger(tsc01)); } // Checks if the speed is above a certain amount if (msc01.Achieved == false && msc01.Active == false && WorkoutCalculations.CalculateSpeed(Bike.Instance.RPM) >= msc01.Speed) { float startTime = Time.time; msc01.Active = true; StartCoroutine(MaintainSpeedTracker(msc01, startTime)); } /* * if(rpc01.Achieved == false && FINALRANKPLACEHOLDER <= rpc01.Rank && raceEnd == true) * { * StartCoroutine(RacePlacementTrigger(rpc01)); * } */ // Checks if a certain amount of distance is achieved if (tdc01.Achieved == false && WorkoutCalculations.CalculateSpeed(Bike.Instance.Count) >= tdc01.Distance) { StartCoroutine(TotalDistanceTrigger(tdc01)); } /* * if(MATCHFINISH == true) * { * SaveSystem.SaveChallengeData(challengeStatuses, calculateDistance()); * } */ }
private void Update() { if (isMultiplayer == true && startFollow == false) { return; } if (isMultiplayer == true) { if (peerId == RealTimeClient.Instance.peerId) { updatedRPM = Bike.Instance.RPM; } } else { updatedRPM = Bike.Instance.RPM; } currentRPM = updatedRPM; speed = WorkoutCalculations.CalculateGameSpeed(currentRPM) + speedOffset; //CalculateSpeed(updatedRPM); //Get rpm from server }