Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 tamsii · Jul 21, 2014 at 10:37 AM · c#guilevels

Locked levels

In my game, I have couple of levels. At the beginning of the game, I want all of them to be locked, except the first one. At the same time I want the locked levels to have different picture than the unlocked ones (this will probably be done with GUI).

How can I do this?

I have the following code in my scene with level map:

 public Texture2D level2_Locked;
 public Texture2D level2_Unlocked;
 public Texture2D level3_Locked;
 public Texture2D level3_Unlocked;

 public int levelReached = 0;
 levelReached = PlayerPrefs.GetInt("SavedLevel");

 void OnGUI () {

     if(levelReached == 2)
     {
         GUI.Label (new Rect (500,300,50,40),level2_Unlocked);
     }

     else if(levelReached == 1)
     {
         GUI.Label (new Rect (500,300,50,40),level2_Locked);
     }
     if(levelReached == 3)
     {
         GUI.Label (new Rect (500,300,50,40),level3_Unlocked);
     }
     
     else if(levelReached == 0)
     {
         GUI.Label (new Rect (500,300,50,40),level3_Locked);
     }
 
 }

}

And I have PlayerPrefs.SetInt("SavedLevel", 3); in other script. Is it possible to have sth like this?

Comment
Add comment · Show 1
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
avatar image gjf · Jul 21, 2014 at 10:41 AM 0
Share

do you have any code to display them now? if so, post it so people can suggest where to change/add/etc. please remember to use code tags.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Tehnique · Jul 21, 2014 at 11:52 AM

Make a new object called "LevelIcon" that contains the 2 textures (locked/unlocked), an int property for index and maybe a property "LevelName", for the display name.

Build an Array of such objects, adding an object for each level. In your GUI function, loop through the array, and if the index is < levelReached, show the unlocked texture, else, show the locked one.

Comment
Add comment · Share
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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Why is my GUI pushed over to the right? 0 Answers

Drawing 4 GUIButton's with a forloop. Need help changing color? 1 Answer

GUI objects jitter when following "lerped" Gameobject [SOLVED] 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