Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

playerprefs Issue

Discussion in 'Scripting' started by oldcollins, Jan 18, 2015.

  1. oldcollins

    oldcollins

    Joined:
    Aug 3, 2012
    Posts:
    111
    I'm having a small Issues with playerprefs i've got it so it saves the Score of my game and loads it

    but i'm trying to get to to accumulate scores for an unlock level system any help with this would be great thanks

    and yes i know the code doesn't look good at the moments but its still working process


    MainMenu Level Script
    Code (JavaScript):
    1.  
    2.  
    3. var score : int = 0;
    4.  
    5. var ScoreText : Text;
    6.  
    7. private var MainScore : int = 0;
    8.  
    9.  
    10. function Start ()
    11. {
    12.  
    13.     score = PlayerPrefs.GetInt("Score", score);
    14.  
    15.     MainScore = PlayerPrefs.GetInt("MainScore", score);
    16. }
    17.  
    18. function Update ()
    19. {
    20.  
    21.     ScoreText.text = "Score :" +  score;
    22.     //ScoreText.text = "Score :" +  MainScore;
    23.  
    24.  
    25.     if (score >=10)
    26.     {
    27.         PlayerPrefs.SetInt("MainScore", MainScore);
    28.     }
    29.  
    30.     if (score >=150)
    31.     {
    32.         gameObject.Find("Main Camera").SendMessage("Unlock1");
    33.         PlayerPrefs.SetInt("MainScore", score);  
    34.     }
    35. }
    36.  


    Saved From PlayLevel Script
    Code (JavaScript):
    1.  
    2.  
    3. function SaveScore ()
    4. {
    5.     PlayerPrefs.SetInt("Score", score);
    6. }
    7.  
    8.  
     
  2. oldcollins

    oldcollins

    Joined:
    Aug 3, 2012
    Posts:
    111
    Solved it