Quantcast
Channel: Questions in topic: "count"
Viewing all articles
Browse latest Browse all 187

C# How Add new score to old score in update function

$
0
0
**I have been struggling to get my head round to adding my new score to the old score in update function with Mathf.move towards but not work! score increase to infinity, I use bool, while, limited time nothing work please help me, I want to add remaining time left + current score.** void Start() { LevelNumber = SceneManager.GetActiveScene().buildIndex; timertext.text = "00:" + secondLeft; nextTime = Time.time + delay + 2; VictoryPanel.SetActive(false); GameOverPanel.SetActive(false); cam = GameObject.FindGameObjectWithTag ("MainCamera").GetComponent(); //cam.Default(); go = false; CountDownAnimimator.SetBool("countdown",true); currentScore = PlayerPrefs.GetFloat("score"); //PlayerPrefs.DeleteAll(); } void Update() { scoretext.text = "Score: " + currentScore.ToString("0"); if(timeleft <= 0) { timeleft = 0; cam.ChangeToEnd(); //Time.TimeScale = 0; //timeisUp.gameObject.SetActive(true); //Restartbutton.gameObject.SetActive(true); } timertext.text = "" + Mathf.Round(timeleft); if (Time.time >= nextTime) { StartCoroutine(SetCollor()); nextTime += interval; } if(timeleft > 0 && Time.time >= nextTime -1) { if(Timer) { timeleft -= Time.deltaTime; go = true; } if(timeleft <= 10) { timertext.color = Red; } if(title1.GetComponent().color == Green ) { cam.ChangeToEnd(); Timer = false; timertext.color = Green; VictoryPanel.SetActive(true); LevelComplete(); StartCoroutine(UpdateScore()); } else if(timeleft <= 0 && Titles[index].GetComponent().color == Red) { cam.ChangeToEnd(); timertext.color = Red; GameOverPanel.SetActive(true); } } if(Time.timeSinceLevelLoad >= delay) { CountDownAnimimator.SetBool("countdown",false); cam.ChangeToPlay(); } } public void RestartLevel() { timeisUp.gameObject.SetActive(false); Restartbutton.gameObject.SetActive(false); Time.timeScale = 1; timeleft = 40; SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); } public void NextLevel() { //timeisUp.gameObject.SetActive(false); //Restartbutton.gameObject.SetActive(false); //Time.timeScale = 1; timeleft = 40; SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1); } public void BackToMenu() { //timeisUp.gameObject.SetActive(false); //Restartbutton.gameObject.SetActive(false); //Time.timeScale = 1; timeleft = 40; SceneManager.LoadScene("Menu"); } IEnumerator SetCollor() { for (int i = 0; i < Titles.Length; i++) { while(used.Contains(index)) { index = Random.Range (0,Titles.Length); yield return null; } } used.Add (index); Titles[index].GetComponent().color = Red; } void Finish() { //GameObject.Find("Player").SendMessage("Finish"); timertext.color = Green; } void LevelComplete() { if(PlayerPrefs.GetInt("MaxLevel") == LevelNumber) { PlayerPrefs.SetInt("MaxLevel", PlayerPrefs.GetInt("MaxLevel") + 1); } } IEnumerator UpdateScore() { Count = Mathf.MoveTowards(Count, timeleft, Time.deltaTime * 3.0f ); currentScore = currentScore + Count; yield return new WaitForSeconds(0.1f); PlayerPrefs.SetFloat("score",currentScore); PlayerPrefs.Save (); } }**strong text**

Viewing all articles
Browse latest Browse all 187

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>