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

Why this middle code doesnt want to run, Playerpref problem

$
0
0
I wanted to SetActive the star3 in level button UI after play game. Unfortunatelly it only can active to 2 levels, the last level which is level 3 didnt happen. So weird. Does anyone know why? ---------- using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; public class LevelControl : MonoBehaviour { public Button level02Button, level03Button; int levelPassed; public GameObject star1, star2, star3; void Start () { levelPassed = PlayerPrefs.GetInt ("LevelPassed"); level02Button.interactable = false; level03Button.interactable = false; if (levelPassed == 15) { level02Button.interactable = true; level03Button.interactable = false; star1.SetActive(true); //WORKING Debug.Log("Star level 1 is shown"); } if (levelPassed == 21) { level02Button.interactable = true; level03Button.interactable = true; star1.SetActive(true); star2.SetActive(true); //WORKING Debug.Log("Star Level 2 is shown"); } if (levelPassed == 26) { star1.SetActive(true); star2.SetActive(true); star3.SetActive(true); //NOT WORKING Debug.Log("Star level 3 is shown"); // IM SURE THAT I ALREADY PASS THE LEVEL 26, WITH IS LEVEL 3. STILL STAR LEVLE 3 NOT UPDATE. } } public void levelToLoad (int level) { UnityEngine.SceneManagement.SceneManager.LoadScene (level); } public void resetPlayerPrefs() { PlayerPrefs.DeleteAll (); } }

Viewing all articles
Browse latest Browse all 1333

Trending Articles



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