// 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; } } }
// Start is called before the first frame update private void Start() { PlayerPrefs.SetInt("TopSpeed1", 0); PlayerPrefs.SetInt("MaintainSpeed1", 0); PlayerPrefs.SetInt("RacePlacement1", 0); PlayerPrefs.SetInt("TotalDistance1", 0); PlayerPrefs.SetInt("DailiesCompleted", 0); tsc01 = new TopSpeed(topSpeedImage, 20); msc01 = new MaintainSpeed(maintainSpeedImage, 10, 30); rpc01 = new RacePlacement(racePlacementImage, 3); tdc01 = new TotalDistance(totalDistanceImage, 2); dcc01 = new DailiesCompleted(dailiesCompletedImage); }
IEnumerator MaintainSpeedTrigger(MaintainSpeed challenge) { PlayerPrefs.SetInt("MaintainSpeed1", 1); challengeImage.GetComponent <RawImage>().texture = challenge.Image.GetComponent <RawImage>().texture; challengeTitle.GetComponent <Text>().text = challenge.Title; challengeDescription.GetComponent <Text>().text = challenge.Description; challengePanel.SetActive(true); yield return(new WaitForSeconds(7)); challengePanel.SetActive(false); challengeTitle.GetComponent <Text>().text = ""; challengeDescription.GetComponent <Text>().text = ""; }