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

[HELP]Saving incremental game upgrades using PlayerPrefs

Discussion in 'Scripting' started by Grehgous, Jul 23, 2015.

  1. Grehgous

    Grehgous

    Joined:
    Jul 23, 2015
    Posts:
    2
    I've made a basic incremental game loosely following these tutorials:

    This is my first time using unity.

    I essentially have 10 buttons to purchase different gold per second upgrades, and 10 buttons for purchasing gold per click upgrades. Each can be purchased multiple times (leveled up), and the price increases with each purchase.

    I currently have it so that PlayerPrefs saves the current gold, but I can not figure out how to have it save the information for each button ( ex. number owned and cost), since the UI buttons are all running the same scripts.

    I have one script which controlls gpcUpgrades, and another for gpsUpgrades, so I do not know how I would save the instances of each class. I am trying to save the level and cost for each one.



     
    Last edited: Jul 23, 2015
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    Name the UI buttons and use that to reference what the data is representing?
     
  3. Grehgous

    Grehgous

    Joined:
    Jul 23, 2015
    Posts:
    2
    Is this the correct way? Where I just link the just the one to each button?




    When I do it this way I am unable to do gpcUpgrade7.level for example
     
    Last edited: Jul 23, 2015
  4. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    uhh... maybe? Not really sure what you're trying to demonstrate here.

    I simply meant you could do something like:
    Code (csharp):
    1.  
    2. PlayerPrefs.SetInt(button.gameObject.name, button.value);
    3.  
    4. and
    5.  
    6. button.value = PlayerPrefs.GetInt(button.gameObject.name);
    7.