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

count score start 0

$
0
0
i create game, when a ball touch a object score.text show the score=10 but i have a problem when the game is over and i start again to play the ball when touch object its start score 10 again etc i don't want it i need wen game over and i touch again a ball score continue to count where its finished like when a score is 60 and game over and i pray again score start to 70 , public class BallContollers : MonoBehaviour { public int scorevalue; **Ballcontroler.cs** private GameManager gameManager; void OnTriggerEnter(Collider col){ if (col.gameObject.tag == "Diamond") { Destroy (col.gameObject); Destroy (part, 1f); gameManager.AddScore (scorevalue); } } **gamemanager.cs** public Text scoreText; private int Scores; void Start () { Scores = 0; scoreText.text = PlayerPrefs.GetInt ("ScoreText").ToString(); PlayerPrefs.SetInt ("ScoreText", Scores); } public void updatescore(){ if (Scores > PlayerPrefs.GetInt ("ScoreText")) { //IncrementScore (); } scoreText.text = "" + Scores; } public void AddScore(int newscorevalue){ Scores+= newscorevalue; PlayerPrefs.SetInt ("ScoreText", Scores); updatescore (); } }

Viewing all articles
Browse latest Browse all 187

Trending Articles



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