So at the moment, I'm making a small little mobile game and I have a scorer working. What I want to do is to make the scorer accelerate (score faster) when the numerical value of score has reached a certain threshold. I used a vector3 to represent the 3 thresholds at which point the scorer will score faster. The problem is, whenever the score has reached threshold#1, it stops counting. Can someone please evaluate my script? Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class TextController : MonoBehaviour { public GameObject Player; public Vector3 ScoreTargets; private float Score; public Text Self; IEnumerator Scorer(){ while(Score < ScoreTargets.x){ Score += 25; Debug.Log(Score); yield return new WaitForSeconds(.1f); } while(Score < ScoreTargets.y && Score > ScoreTargets.x){ Score += 100; Debug.Log(Score); yield return new WaitForSeconds(.1f); } while(Score < ScoreTargets.z && Score < ScoreTargets.y && Score < ScoreTargets.x){ Score += 150; Debug.Log(Score); yield return new WaitForSeconds(.1f); } yield return new WaitForSeconds(1); } void Start () { StartCoroutine("Scorer"); } // Update is called once per frame void Update () { Self.text = "Score: " + Score; } } here's a little video of what's happening. Just skip near the end to see the counter stop
Hi. You could try adding Debug.Log statements or using breakpoints to see clearer what is happening. One cause though might be line 19 that should perhaps read (>=): while(Score < ScoreTargets.y && Score >= ScoreTargets.x){ if Score equals ScoreTargets.x i.e. 1000 to exit the first condition then the second while loop would never run as Score is not greater than 1000, only equal. Regards, Mark ----- Check out my assets: Game Framework (Free), Beautiful Transitions and more...