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 andrer11444 · Feb 14, 2021 at 08:14 PM · playerprefslevelvalues

Value changes after using it in another script, why?

Hello

I finally could solve my problem with playerpref, but now i have a new problem.

I have the playerpref value and want to compare it with the value i put on every "LevelImage".

But as soon i click for example on Level 3 it changes the value 4 to 7. i put everthing into the console so i can see whats happening with my values.

here are the two scripts.

public class AktuellesLevel : MonoBehaviour {

 public int Level;

 // Start is called before the first frame update
 void Start()
 {
     Level = GetComponent<AktuellesLevel>().Level;
    

 }

 // Update is called once per frame
 void Update()
 {
     
 }

 public void OnTriggerEnter2D(Collider2D collision)
 {

    

     Debug.Log(Level);
  
    

 }

}

And here the second

public class LoadManager : MonoBehaviour { private string LevelChoice; private AktuellesLevel AL; public int aktuellesLevel;

 // Start is called before the first frame update
 private void Start()
 {
     AL = FindObjectOfType<AktuellesLevel>();
     aktuellesLevel = PlayerPrefs.GetInt("farthestLevel");

 }

 // Update is called once per frame
 void Update()
 {
     if (Input.GetMouseButtonDown(1))
     {
         if (AktuellesLevel > AL.Level)
         {
             Select();
         }
         else
         {
             Debug.Log("Vorheriges Level noch nicht abgeschlossen");
         }
     }
 }

 public void Select()
 {


     Debug.Log(AL.Level);
     Debug.Log(AktuellesLevel);

     SceneManager.LoadScene(LevelChoice);
     
 }

 public void OnTriggerEnter2D(Collider2D collision)
 {
   
     LevelChoice = collision.name;
   
     
     
 }

 

 public void Hauptmeue()
 {
     SceneManager.LoadScene(0);
 }

In the second script i shouldt even be able to choose level3 but it is still loading. And after loading the value AL.Level is 7, not 4 how i set it in the inspector.

I hope someone can help me. I try for a long time now to make to player play each level after another, i seems really complicated to me.

Thanks

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Megaboy238 · Feb 14, 2021 at 08:53 PM

You are passing a string to the SceneManager so it will be selecting by Scene Name not index number, check the names are correct in File > Build Settings

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 andrer11444 · Feb 15, 2021 at 02:42 PM 0
Share

Hello

Thanks for your input. I know about the string, but the select method shouldnt run if the two values i try to compare are not equal.

But now while i am typing this, i could just change the string into a value and compare this with playerpref...ill try that, the value just needs to be the same like in the build settings

Thanks for triggering my brain :)

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

117 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 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 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 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

save game using player prefs 2 Answers

HOW to PlayerPrefs.DeleteAll () in that only level ? HELP 0 Answers

Why this middle code doesnt want to run, Playerpref problem 0 Answers

Leveling up and Unlockables 0 Answers

Storing in PlayerPref based on timer 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