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 Heratitan · Jul 27, 2010 at 11:59 PM · playerprefsbooleanlevellockunlock

PlayerPrefs Problem crashing with SetBool

Hello, so to finish off my game (iPhone Game) I added a lock/unlocking system for levels using the PlayerPrefs. Currently when I play the game it crashes when I touch an object that I can pick up, probably because it is trying to update the score, and also this only happens when the playerprefs are in my script. My script is also not updating the playerprefs for some reason.

Does anyone know why this is happening?

Mainscript:

var LE1 = PlayerPrefsX.GetBool("LevelOneEnabled"); var LE2 = PlayerPrefsX.GetBool("LevelTwoEnabled"); var LE3 = PlayerPrefsX.GetBool("LevelThreeEnabled"); var LE4 = PlayerPrefsX.GetBool("LevelFourEnabled"); var LE5 = PlayerPrefsX.GetBool("LevelFiveEnabled"); var LE6 = PlayerPrefsX.GetBool("LevelSixEnabled"); var LE7 = PlayerPrefsX.GetBool("LevelSevenEnabled"); var LE8 = PlayerPrefsX.GetBool("LevelEightEnabled"); var LE9 = PlayerPrefsX.GetBool("LevelNineEnabled"); var LE10 = PlayerPrefsX.GetBool("LevelTenEnabled");

var GUIicon1 : Texture2D; var GUIicon2 : Texture2D; var GUIicon3 : Texture2D; var GUIicon4 : Texture2D; var GUIicon5 : Texture2D; var GUIicon6 : Texture2D; var GUIicon7 : Texture2D; var GUIicon8 : Texture2D; var GUIicon9 : Texture2D; var GUIicon10 : Texture2D;

function OnGUI () {
GUI.enabled = LE1; if (GUI.Button(Rect(120,100,40,40), (GUIicon1))) { Application.LoadLevel(11); } GUI.enabled = LE2; if (GUI.Button(Rect(170,100,40,40), (GUIicon2))) { Application.LoadLevel(12); } GUI.enabled = LE3; if (GUI.Button(Rect(220,100,40,40), (GUIicon3))) { Application.LoadLevel(13); } GUI.enabled = LE4; if (GUI.Button(Rect(270,100,40,40), (GUIicon4))) { Application.LoadLevel(14); } GUI.enabled = LE5; if (GUI.Button(Rect(320,100,40,40), (GUIicon5))) { Application.LoadLevel(15); } GUI.enabled = LE6; if (GUI.Button(Rect(120,175,40,40), (GUIicon6))) { Application.LoadLevel(16); } GUI.enabled = LE7; if (GUI.Button(Rect(170,175,40,40), (GUIicon7))) { Application.LoadLevel(17); } GUI.enabled = LE8; if (GUI.Button(Rect(220,175,40,40), (GUIicon8))) { Application.LoadLevel(18); } GUI.enabled = LE9; if (GUI.Button(Rect(270,175,40,40), (GUIicon9))) { Application.LoadLevel(19); } GUI.enabled = LE10; if (GUI.Button(Rect(320,175,40,40), (GUIicon10))) { Application.LoadLevel(20); } GUI.enabled = true; }

Updating Playerprefs Script:

private function EndGame() { var animationController : AnimationController = GetComponent( AnimationController ); var prefab : GameObject = Instantiate(guiMessage); var endMessage : GUIText = prefab.GetComponent( GUIText );

 if(carrying >= winScore)
 {
     //Player wins
     endMessage.text = "You win!";
     PlayAudioClip( winSound, Vector3.zero, 1.0 );
     // animationController.animationTarget.Play( "WIN" );
     if (level == 1){
     PlayerPrefsX.SetBool("LevelTwoEnabled", true);
     }
     if (level == 2){
         PlayerPrefsX.SetBool("LevelThreeEnabled", true);
     }
     if (level == 3){
         PlayerPrefsX.SetBool("LevelFourEnabled", true);
     }
     if (level == 4){
         PlayerPrefsX.SetBool("LevelFiveEnabled", true);
     }
     if (level == 5){
         PlayerPrefsX.SetBool("LevelSixEnabled", true);
     }
     if (level == 6){
         PlayerPrefsX.SetBool("LevelSevenEnabled", true);
     }
     if (level == 7){
         PlayerPrefsX.SetBool("LevelEightEnabled", true);
     }
     if (level == 8){
         PlayerPrefsX.SetBool("LevelNineEnabled", true);
     }
     if (level == 9){
         PlayerPrefsX.SetBool("LevelTenEnabled", true);
     }
 }
 else
 {
     //Player loses
     endMessage.text = "You Lose";
     PlayAudioClip( loseSound, Vector3.zero, 1.0 );      
     // animationController.animationTarget.Play( "LOSE" );      
 }
 // Alert other components on this GameObject that the game has ended
 SendMessage( "OnEndGame" );

 while( true )
 {
     // Wait for a touch before reloading the intro level
     yield WaitForFixedUpdate();
     if ( iPhoneInput.touchCount > 0 && iPhoneInput.GetTouch( 0 ).phase == iPhoneTouchPhase.Began )
         break;
 }

 Application.LoadLevel( 22 );

}

Also here is a link to the boolean playerprefs script: http://www.unifycommunity.com/wiki/index.php?title=BoolPrefs

Thanks.

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 qJake · Jul 28, 2010 at 02:53 AM 0
Share

Wow dude, you seriously need to learn how to use arrays... Copy-pasting code is a sin.

2 Replies

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

Answer by Heratitan · Jul 28, 2010 at 02:12 AM

Ok, I found your problem. What you did is you put your variables LE1, LE2... into your script, representing your playerprefs. What you need to do is put the playerprefs directly in like so:

GUI.enabled = PlayerPrefsX.GetBool("LevelOneEnabled"); 
  if (GUI.Button(Rect(120,100,40,40), (GUIicon1)))
  {
    Application.LoadLevel(11);
  }

Hope that helps

Comment
Add comment · Show 1 · 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 Heratitan · Jul 28, 2010 at 02:13 AM 0
Share

It did thanks. =)

avatar image
0

Answer by sooryan · Jan 08, 2013 at 11:44 AM

How to do this with arrays.I Have around 50 levels

Comment
Add comment · Show 1 · 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 AlucardJay · Jan 08, 2013 at 11:44 AM 0
Share

Please don't post comments as answers. Post comments by clicking the [add new comment] button, a window then open for you to type in. Answer fields are for answers only, as this is a knowledge base.

You can convert this answer to a comment (or just edit your original question), you'll also get a better chance of getting an actual answer if the main list shows none or one answer in blue =]

Under the answer where it says edit | delete | more , click on more , then convert to comment

Also you don't have to wait for a moderator to approve a comment.

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

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

Set boolean to true from another scene 1 Answer

Purchase Level Unlock System 1 Answer

Who can help me with lock/unlock and hint/coin systems? 0 Answers

stumped on level unlock 0 Answers


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