I am trying to make a statistic menu in my game which will show you stats about your progress in the game. I am trying to make a text that will tell you how much time you have played the game.
#pragma strict
import UnityEngine.UI;
static var gamesPlayed : int;
var gamesPlayedText : UI.Text;
function Start () {
gamesPlayed = gamesPlayedText.ToInt();
gamesPlayedText = GetComponent(UI.Text);
gamesPlayedText.text = PlayerPrefs.GetInt("gamesPlayedText",0).ToString();
}
function Update ()
{
PlayerPrefs.SetInt ("gamesPlayedText", gamesPlayed);
gamesPlayedText.text = gamesPlayed.ToString();
}
The problem with this script is that I want it to set the gamesPlayed variable to the gamesPlayedText variable so it won’t go back to 0 whenever I leave the game and go back in. I know that there is a ToString() but when I try ToInt() it gives me an error that it doesn’t exist. So Is there a way to make a UI Text an integer?
Please answer and Thanks in advance.