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 /
  • Help Room /
avatar image
0
Question by Fazle_Rabbi · Sep 28, 2015 at 01:26 PM · javascripttextureloopunity4

How to disable LockTexture in case of LEVEL UNLOCK SYSTEM IN UNITY?

am building a game consist of 8 level. I use the following script to switch next level. But when i unlock a level the Lock Texture still remain in the window. I want to remove the lock texture when i unlock a new level. Please help me out. Thanks in advance. The full script is look like this:

     var TitleText:String = "SINGLE PLAYER";
     var NumberOfPlayers:int = 1;
 
     var Levels:int = 8;
     private var LevelIndex:int = 0;
 
     var PointsToUnlock:Array = new Array(0, 2, 6, 12, 24, 36, 48, 56);
 
     var LevelsGrid:Vector2 = Vector2(4,2);
     private var GridIndexA:int = 0;
     private var GridIndexB:int = 0;
 
     var LevelTexture:Texture2D;
     var LockTexture:Texture2D;
 
     //~ var HowToPlayTexture:Texture2D;
     var BGPattern:Texture2D;
 
     //This script displays the HUD, with current weapon, ammo left, Health, Shield, and score
     var GUIskin:GUISkin; //The skin gui we'll use
 
     private var LevelPoints:Array = new Array();
     private var TotalPoints:int = 0;
 
     function Start()
     {
         if ( camera.main.GetComponent("StartMenu") )
             camera.main.GetComponent("StartMenu").MenuLevel = transform;
         else if ( camera.main.GetComponent("EndMenu") )
             camera.main.GetComponent("EndMenu").MenuLevel = transform;
         
         LevelPoints.Clear();
         
         for ( LevelIndex = 1 ; LevelIndex <= transform.GetComponent("LevelsMenu").Levels ; LevelIndex++ )
         {
             LevelPoints.Push(PlayerPrefs.GetInt(("level" + LevelIndex + "Points").ToString()));
         
             TotalPoints += LevelPoints[LevelIndex - 1];
         }
         
         print(LevelPoints);
         print(TotalPoints);
     }
 
     function OnGUI()
     {
         GUI.skin = GUIskin; //The skin gui we'll use
         GUI.depth = 0;
         
         GUI.DrawTexture(Rect( 0, 0 ,Screen.width, Screen.height), BGPattern);//Laps.ToString() + "/" + GameController.GetComponent("GameController").LapsToWin.ToString()); //Draw the HUD texture
         
         GUI.Label(Rect(0, 10, Screen.width, 70), TitleText);
         
         LevelIndex = 0;
         
         for ( GridIndexB = 0 ; GridIndexB < LevelsGrid.y ; GridIndexB++ )
         {
             for ( GridIndexA = 0 ; GridIndexA < LevelsGrid.x ; GridIndexA++ )
             {
                 LevelIndex++;
                 
                 GUI.DrawTexture(Rect( (Screen.width - LevelsGrid.x * (LevelTexture.width + 10)) * 0.5 + GridIndexA * (LevelTexture.width + 10), 60 + GridIndexB * (LevelTexture.height + 10) ,LevelTexture.width, LevelTexture.height), LevelTexture);//Laps.ToString() + "/" + GameController.GetComponent("GameController").LapsToWin.ToString()); //Draw the HUD texture
                 
                 if ( TotalPoints >= PointsToUnlock[LevelIndex - 1] )
                 {
                     if ( GUI.Button(Rect( (Screen.width - LevelsGrid.x * (LevelTexture.width + 10)) * 0.5 + GridIndexA * (LevelTexture.width + 10), 60 + GridIndexB * (LevelTexture.height + 10), LevelTexture.width, LevelTexture.height), LevelIndex.ToString()) )//Laps.ToString() + "/" + GameController.GetComponent("GameController").LapsToWin.ToString()); //Draw the HUD texture
                     {
                         PlayerPrefs.SetInt("currentLevel", LevelIndex); 
                         Application.LoadLevel("level" + LevelIndex);
                         
                     }
                 }
                 else
                 {
                     GUI.DrawTexture(Rect( (Screen.width - LevelsGrid.x * (LevelTexture.width + 10)) * 0.5 + GridIndexA * (LevelTexture.width + 10), 60 + GridIndexB * (LevelTexture.height + 10), LevelTexture.width, LevelTexture.height), LockTexture);
                 }
             }
         }
         
         if ( GUI.Button(Rect( 10, Screen.height - 70, 140, 60), "BACK") )//Laps.ToString() + "/" + GameController.GetComponent("GameController").LapsToWin.ToString()); //Draw the HUD texture
         {
             if ( camera.main.GetComponent("StartMenu") )
                 camera.main.GetComponent("StartMenu").MenuLevel = camera.main.transform;
             else if ( camera.main.GetComponent("EndMenu") )
                 camera.main.GetComponent("EndMenu").MenuLevel = camera.main.transform;
                 
             Destroy(gameObject);
         }
         
         if ( GUI.Button(Rect( Screen.width - 410 , Screen.height - 70, 400, 60), "RESET LEVELS") )//Laps.ToString() + "/" + GameController.GetComponent("GameController").LapsToWin.ToString()); //Draw the HUD texture
         {
              LevelPoints.Clear();
             
              for ( LevelIndex = 1 ; LevelIndex <= transform.GetComponent("LevelsMenu").Levels ; LevelIndex++ )
              {
                  PlayerPrefs.SetInt(("level" + LevelIndex + "Points").ToString(), 0);
              }
             
             //~ TotalPoints = 0;
         }
     }




I am going to make it easy for you. I just need a simple line of code in the following loop where i can disable LockTexture when new level come up.

 LevelIndex = 0;
 
     for ( GridIndexB = 0 ; GridIndexB < LevelsGrid.y ; GridIndexB++ )
     {
         for ( GridIndexA = 0 ; GridIndexA < LevelsGrid.x ; GridIndexA++ )
         {
             LevelIndex++;
 
             GUI.DrawTexture(Rect( (Screen.width - LevelsGrid.x * (LevelTexture.width + 10)) * 0.5 + GridIndexA * (LevelTexture.width + 10), 60 + GridIndexB * (LevelTexture.height + 10) ,LevelTexture.width, LevelTexture.height), LevelTexture);//Laps.ToString() + "/" + GameController.GetComponent("GameController").LapsToWin.ToString()); //Draw the HUD texture
 
             if ( TotalPoints >= PointsToUnlock[LevelIndex - 1] )
             {
                 if ( GUI.Button(Rect( (Screen.width - LevelsGrid.x * (LevelTexture.width + 10)) * 0.5 + GridIndexA * (LevelTexture.width + 10), 60 + GridIndexB * (LevelTexture.height + 10), LevelTexture.width, LevelTexture.height), LevelIndex.ToString()) )//Laps.ToString() + "/" + GameController.GetComponent("GameController").LapsToWin.ToString()); //Draw the HUD texture
                 {
                     PlayerPrefs.SetInt("currentLevel", LevelIndex); 
                     Application.LoadLevel("level" + LevelIndex);
 
                 }
             }
             else
             {
                 GUI.DrawTexture(Rect( (Screen.width - LevelsGrid.x * (LevelTexture.width + 10)) * 0.5 + GridIndexA * (LevelTexture.width + 10), 60 + GridIndexB * (LevelTexture.height + 10), LevelTexture.width, LevelTexture.height), LockTexture);
             }
         }
     }


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

30 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

Related Questions

How to loop folders in directory 1 Answer

Array index is out of range. 1 Answer

Base64 to texture decoding, js -> webgl 1 Answer

Why wont my script instantiate multiple instances? 1 Answer

How to change a variable used in a loop for the outside ? 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