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 darthvaderxd · Feb 22, 2015 at 09:42 PM · scorelockunlock

how can i make one system that unlock levels by points?

In my game I have 10 levels. Each level has coins I'd like to use to unlock the next levels.

For example:

level 2: 10 coins

level 3: 20 coins

and so on ... how could I do that? Thanks in advance.

Comment
Add comment · Show 3
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 karljj1 · Feb 22, 2015 at 09:44 PM 1
Share

What have you tried so far? Do you need help keeping track of the number of coins collected between scenes? PlayerPrefs is a good way to do this.

avatar image darthvaderxd · Feb 23, 2015 at 03:17 AM 0
Share

I watch a video in youtube that taught about playerPrefs to save the colors of a cube.

He uses the following script:

pragma strict

var SavedColor;

function Start ()

{ SavedColor = PlayerPrefs.GetString("Color");

if(SavedColor != null)

{

 if(SavedColor == "Yellow")

 {

    renderer.material.color = Color.yellow;

 }

    else

   {

    renderer.material.color = Color.red;

   }

}

}

function Update ()

{

}

function OnGUI()

{

if(GUI.Button(Rect(100, 100, 100, 100),"Yellow"))

{

 renderer.material.color = Color.yellow;

 Save("Yellow");

}

if(GUI.Button(Rect(100, 200, 100, 100),"Red"))

{

 renderer.material.color = Color.red;

 Save("Red");

}

}

I think that with a few changes I can use this same script, just don't know where to begin

avatar image skylem · Feb 23, 2015 at 03:14 PM 0
Share

PlayerPrefs are just values are values that are held outside of scripts u can save Floats(decimal number values) ints(rounded number values) and strings(custom text), u do this like so.

 //do this somewhere when u want to save
 PlayerPrefs.SetString("Save/LoadName", "custom text to save");
 
 // do this when u want to load it StartFunction is good for this as it only fires once.
 string savedtext = PlayerPrefs.GetString("Save/LoadName");
 Debug.Log(savedtext); // show what we loaded in the console.
 
 PlayerPrefs.SetFloat("PositionX", transform.position.x);
 float savedXPosition = PlayerPrefs.GetString("PositionX");
 
 PlayerPrefs.SetFloat("ExperiencePoints", currentXP);
 currentXP = PlayerPrefs.GetString("ExperiencePoints");

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by skylem · Feb 23, 2015 at 05:25 AM

Quite a simple goal really but how you go about it would depend upon how you setup your Levels and how the player accesses them for example if you click the levels from a main menu i've written a small example that assumes your levels are accessed by GUI but you should be able to make simple changes to implement it for your desired use.

 // points we're checking.
 int points;
 
 // gui to be placed in OnGUI to enabled/disable buttons.
 
 // check if we have 10 points
 if(points > 10) {
 // if we do have 10 points display a gui button for level 2
    if(GUI.Button(new Rect(100,175,110,25),"Level 2")) {
 Application.LoadLevel("1");
 }
 }
 // the same as above except the points we check is 20 and
 // the position height of the gui is a different value so
 // they do not overlap, u can also use GUILayout to spread
 // these buttons out over an area but i left it out as not
 // to over complicate.
 if(points > 20) {
    if(GUI.Button(new Rect(100,205,110,25),"Level 3")) {
 Application.LoadLevel("2");
 }
 }
Comment
Add comment · Show 3 · 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
avatar image darthvaderxd · Feb 23, 2015 at 02:57 PM 0
Share

this seems to be a good idea, now I have a point to start, thank you very much :)

avatar image skylem · Feb 23, 2015 at 03:04 PM 0
Share

no problem, when i first started i also had little to know idea on how to begin a concept, just something that kicks in when you learn a bit. and the best way to learn is by doing have fun if u require further help you can email me anytime Skylem@live.com.au

avatar image darthvaderxd · Feb 23, 2015 at 03:23 PM 0
Share

I am very grateful for the attention. Have a nice day :D

avatar image
0

Answer by FoneFreak · Jul 24, 2017 at 07:34 AM

Hi friend, can this be applied to characters, ie unlock a character with 100 points? if so please advise if you can

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

6 People are following this question.

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

Related Questions

How do I enable the Android lock screen in developer mode? 1 Answer

Locking and Unlocking a cursor... 2 Answers

Problem about Lock/ Unlock level 2 Answers

PlayerPrefs Problem crashing with SetBool 2 Answers

What's the function of the little lock icon on the Project Browser? 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