Quantcast
Channel: Questions in topic: "playerprefs"
Viewing all articles
Browse latest Browse all 1333

playerprefs not working.

$
0
0
public Text scoretex; public Text scoretex2; //public Text scoretex3; private int score; public InputField username; // Use this for initialization //private Text[] text1 = new Text[4]; public Text text2; public GameObject end1; public GameObject end2; public GameObject end3; public Text[] names; public GameObject end4; public GameObject score2; public int num = 0; public Text text3; public Text text4; public Text text5; void Start(){ text2.text= PlayerPrefs.GetInt ("num").ToString() + " " + PlayerPrefs.GetString ("username") + " " + PlayerPrefs.GetInt ("score").ToString(); } void Update () { if (num == 0) { text2.enabled = false; text3.enabled = false; text4.enabled = false; text5.enabled = false; } if (num == 1) { text2.enabled= true; text2.text = PlayerPrefs.GetInt ("num") + " " + PlayerPrefs.GetString ("username") + " " + PlayerPrefs.GetInt ("score"); } if (num == 2) { text3.enabled = true; text3.text = PlayerPrefs.GetInt ("num") + " " + PlayerPrefs.GetString ("username") + " " + PlayerPrefs.GetInt ("score"); } if (num == 3) { text4.enabled = true; text4.text = PlayerPrefs.GetInt ("num") + " " + PlayerPrefs.GetString ("username") + " " + PlayerPrefs.GetInt ("score"); } if (num == 4) { text5.enabled = true; text5.text = PlayerPrefs.GetInt ("num") + " " + PlayerPrefs.GetString ("username") + " " + PlayerPrefs.GetInt ("score"); } } // Update is called once per frame public void Score1 () { scoretex.text = "Score: " + score; scoretex2.text = "Score: " + score; } public void AddScore (int newscore2) { score += newscore2; Score1(); } public void Click1() { num++; if (username != null&& num==1) { text2.text = num.ToString () + " " + username.text + " " + score.ToString (); PlayerPrefs.SetInt ("score", score); PlayerPrefs.SetString ("username", username.text); PlayerPrefs.SetInt ("num", num); end1.SetActive (false); end2.SetActive (false); end3.SetActive (false); end4.SetActive (true); } if (username != null&& num==2) { text3.text = num.ToString () + " " + username.text + " " + score.ToString (); num++; PlayerPrefs.SetInt ("score", score); PlayerPrefs.SetString ("username", username.text); PlayerPrefs.SetInt ("num", num); end1.SetActive (false); end2.SetActive (false); end3.SetActive (false); end4.SetActive (true); } if (username != null&& num==3) { text4.text = num.ToString () + " " + username.text + " " + score.ToString (); num++; PlayerPrefs.SetInt ("score", score); PlayerPrefs.SetString ("username", username.text); PlayerPrefs.SetInt ("num", num); end1.SetActive (false); end2.SetActive (false); end3.SetActive (false); end4.SetActive (true); } if (username != null&& num==4) { text5.text = num.ToString () + " " + username.text + " " + score.ToString (); num++; PlayerPrefs.SetInt ("score", score); PlayerPrefs.SetString ("username", username.text); PlayerPrefs.SetInt ("num", num); end1.SetActive (false); end2.SetActive (false); end3.SetActive (false); end4.SetActive (true); } else end1.SetActive (false); end2.SetActive (false); end3.SetActive (false); end4.SetActive (true); return; } public void Click2() { score2.SetActive (true); if (num == 1) { text2.enabled= true; } if (num == 2) { text3.enabled= true; } if (num == 3) { text4.enabled= true; } if (num == 4) { text5.enabled = true; } } public void ClickClose() { score2.SetActive (false); } }

Viewing all articles
Browse latest Browse all 1333

Latest Images

Trending Articles



Latest Images