hi guys, I am new to dev and trying to figure out a code. Well i am storing game score in UIText name TotalScore. So what i want is to check score when timer ends and active or deactivate specific game object after checking score. Text CurrentScore i am passing TotalScore to it. But how to compare Text to Int? Please help. using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class MySCMnager : MonoBehaviour { void Awake() { PlayerPrefs.SetInt ("TotalScores", (0)); } public float StageTimer; public GameObject Winner; public GameObject Looser; public int TargetScore; public Text CurrentScore; void Start() { Winner.gameObject.SetActive (false); Looser.gameObject.SetActive (false); //StageTimer = 5.0f; } void Update() { StageTimer -= Time.deltaTime; if (StageTimer <= 0.0f) { WinnerCheck (); } } void WinnerCheck() { if (CurrentScore >= TargetScore) { Winner.gameObject.SetActive (true); } else { Looser.gameObject.SetActive (true); } } } }
Hi @hasnain9211 You'll find out how to store score and show it (and other stuff too) in several learn section tutorials, like this one: https://unity3d.com/learn/tutorials/s/roll-ball-tutorial P.S. Use code tags when posting to forums, like you see in other posts. https://forum.unity.com/threads/using-code-tags-properly.143875/
Don't ever save scores as strings. When you need to update a text field convert the score int to a string by using ToString() For example: scoreText.text = TotalScore.ToString(); Also it's Loser not Looser