Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by theunsigned · Mar 07, 2019 at 02:07 PM · levellevelsunlock

stumped on level unlock

I followed a tutorial on level unlocking; it's supposed to unlock the next level if the player gets at least one star on the game. It works for level 1 but then just unlocks the next level if the level is played from level 2 on. I'm going crosseyed trying to figure this out and figured I'd just ask what my error is. Forgive the comments, I'm using them as I learn.

    //fill information based on level class
     public void FillList()
     {
 
 
         //Destroy(GameObject.FindWithTag("LevelButton"));
         //get all components to add, for each variable in the list called LevelList
         foreach(var level in LevelList)
         {
             //instantiate and populate each button, establish which information goes into it
             GameObject newbutton = Instantiate(levelButton) as GameObject;
             //connect new button prefab to levelbutton c# script and call new button gameobject "button"
             LevelButton button = newbutton.GetComponent<LevelButton>();
             //set button prefab text element to leveltext in inspector
             button.LevelText.text = level.LevelText;
 
             //if level text contains a 1, then make it unlocked and make it interactable
             if(PlayerPrefs.GetInt("Level" +  button.LevelText.text) == 1)
             {
                 level.UnLocked = 1;
                 level.IsInteractable = true;
             }
 
             //if (PlayerPrefs.GetInt("Level" + button.LevelText.text+"_star") >= 1)
             //{
             //    int NextLevel = cl + 1;
             //    PlayerPrefs.SetInt("Level" + NextLevel, 1);
             //    level.UnLocked = 1;
             //    level.IsInteractable = true;
             //}
 
             //update the button, set it as unlocked and interactable from level manager
             button.unlocked = level.UnLocked;
             button.GetComponent<Button>().interactable = level.IsInteractable;
 
             //add a listener for onclick -try to call a function
             button.GetComponent<Button>().onClick.AddListener(() => LoadLevels("Level" + button.LevelText.text));
 
             //activate stars on each button, depending on playerprefs
             if (PlayerPrefs.GetInt("Level" + button.LevelText.text + "_star") >= 1)
                 {
                 button.Star1.SetActive(true);
 
                 int NextLevel = cl + 1;
                 PlayerPrefs.SetInt("Level" + NextLevel, 1);
 
                 level.UnLocked = 1;
                 level.IsInteractable = true;
                 }
             if (PlayerPrefs.GetInt("Level" + button.LevelText.text + "_star") >= 2)
                 {
                     button.Star2.SetActive(true);
                 }
             if (PlayerPrefs.GetInt("Level" +button.LevelText.text + "_star") == 3)
                 {
                     button.Star3.SetActive(true);
                 }
 
 
             //at last step, put new buttons under spacer parent, including transform info
             newbutton.transform.SetParent(Spacer);
         }
         Saveall();
     }
 
 
     //let the button know if it's unlocked, save player prefs 
     //go through every button, check if it's locked or unlocked
     void Saveall()
     {
 
         //if (PlayerPrefs.HasKey("Level1"))
         //{
         //    return;
         //}
         //else
         //{
 
             //tag button prefab with tag and find the objects with that tag, make a gameobject array of them
            GameObject[] allButtons = GameObject.FindGameObjectsWithTag("LevelButton");
             //check each button 
             foreach (GameObject buttons in allButtons)
             {
                 //get Level Button C# script component from prefab
                 LevelButton button = buttons.GetComponent<LevelButton>();
                 //find the right level based on level text, set as unlocked in player prefs
                 PlayerPrefs.SetInt("Level" + button.LevelText.text, button.unlocked);
 
             }
         //}
     }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

101 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why does my level progress reset after clicking the level menu button but doesnt reset after clicking the lvel menu button from the win screen? 1 Answer

Level unlock system 1 Answer

Texturing rooms all the same? 1 Answer

PlayerPrefs not save my unlock button (Levels lock/unlock) 0 Answers

About Creating Levels 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges