Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 Omega2D · Jul 15, 2015 at 08:43 PM · sceneunity5levelloadlevelunlock

Problem to go to another world scene in level select lock/unlock

Hello everyone,

http://www.thegamecontriver.com/2014/09/create-level-lock-unlock-system-unity-46.html#comment-form

I´m follow this tutorial to make a Level lock/unlock system to my game and it´s works but when i finish the levels in the first world, i can´t change/go to the second world scene. My script it´s very similar to the tutorial.

Thank you. The codes it´s here:

My scenes have name: the worlds to select levels:

World1 World2

Levels scenes:

Level1.1 Level1.2 .. Level2.1 Level2.2

first script:

using UnityEngine; using System.Collections;

public class LockLevel : MonoBehaviour {

 public static int worlds = 2; //number of worlds
 public static int levels = 3; //number of levels
 
 private int worldIndex;   
 private int levelIndex;   
 
 
 void  Start (){
     PlayerPrefs.DeleteAll(); //erase data on start
     LockLevels();   //call function LockLevels
 }
 
 //function to lock the levels
 void  LockLevels (){
     //loop thorugh all the levels of all the worlds
     for (int i = 0; i < worlds; i++){
         for (int j = 1; j < levels; j++){
             worldIndex  = (i+1);
             levelIndex  = (j+1);
             //create a PlayerPrefs of that particular level and world and set it's to 0, if no key of that name exists

if(!PlayerPrefs.HasKey("level"+worldIndex.ToString() +":" +levelIndex.ToString())){ PlayerPrefs.SetInt("level"+worldIndex.ToString() +":" +levelIndex.ToString(),0); }
} } } }

Second Script:

using UnityEngine; using System.Collections;

public class LevelSelectScript : MonoBehaviour {

 private int worldIndex;   
 private int levelIndex;   
 
 void  Start (){
     //loop thorugh all the worlds
     for(int i = 1; i <= LockLevel.worlds; i++){
         if(Application.loadedLevelName == "World"+i){
             worldIndex = i;
             CheckLockedLevels(); 
         }
     }
 }
 
 //Level to load on button click. Will be used for Level button click event 
 public void Selectlevel(string worldLevel){
     Application.LoadLevel("Level"+worldLevel); //load the level
 }
 
 //uncomment the below code if you have a main menu scene to navigate to it on clicking escape when in World1 scene
 /*public void  Update (){

if (Input.GetKeyDown(KeyCode.Escape) ){ Application.LoadLevel("MainMenu"); }
}*/

 //function to check for the levels locked
 void  CheckLockedLevels (){
 
     //loop through the levels of a particular world
 
     for(int j = 1; j < LockLevel.levels; j++){
 
         levelIndex = (j+1);
 

if((PlayerPrefs.GetInt("level"+worldIndex.ToString() +":" +levelIndex.ToString()))==1){

             GameObject.Find("LockedLevel"+(j+1)).active = false;
 
             Debug.Log ("Unlocked");
         }
     }
 }

}

Third script: the player part when he comes to the goal:

protected void UnlockLevels (){ //set the playerprefs value of next level to 1 to unlock for(int i = 0; i < LockLevel.worlds; i++){

 Debug.Log(i);
 
 for(int j = 1; j < LockLevel.levels; j++){
 

            
 if(currentLevel == "Level"+(i+1).ToString() +"." +j.ToString()){
 
 worldIndex  = (i+1);
 
 levelIndex  = (j+1);
 
 PlayerPrefs.SetInt("level"+worldIndex.ToString() +":" +levelIndex.ToString(),1);
 
             }
         }
     }
     Application.LoadLevel("World1");

//I try Application.LoadLevel("World1"+((worldIndex+1).ToString)); but doesn´t work

 }
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

2 People are following this question.

avatar image avatar image

Related Questions

How to have GearVR play smooth during LoadLevelAsync 0 Answers

linking levels? 2 Answers

Can I utilize LoadLevelAdditive for immersive game? 2 Answers

Set boolean to true from another scene 1 Answer

UI cycling through my level select 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