- Home /
 
The question is answered, right answer was accepted
How to save different values with same script?
Hello i am making a coockie clicker like game were there is a shop and you can buy different items. I have 2 scripts one for items that add per secound and one that adds a multipler. I have made it so the price increases when i buy items and it works but when im trying to save and load all the items with the same script cost the same
the script: public class SlapModifier : MonoBehaviour { public Text CostT;
     public float Cost;
     public int modifier;
     
 
 
     void Start()
     {
         
 
         Cost = PlayerPrefs.GetFloat("newcostmod");
     }
     public void Update()
     {
         CostT.text = "Cost: " + Cost.ToString("F0");
 
         PlayerPrefs.SetFloat("newcostmod", Cost);
 
     }
     public void Buy()
     {
         GameObject gamemanager = GameObject.Find("GameManager");
         gameManager gamemanagersc = gamemanager.GetComponent<gameManager>();
 
         if(gamemanagersc.currSlaps >= Cost)
         {
             gamemanagersc.currSlaps -= Cost;
             gamemanagersc.slapModifier += modifier;
             Cost *= 1.25f;
         }
 
     }
 
 }
 
 
              Answer by TylerD14 · Nov 17, 2019 at 08:46 PM
@TvattSvampen make Cost a list with Cost[]. notice that I'm not sure about that this works
public Text CostT;
  public float Cost[];
  public int modifier;
  
 
 
  void Start()
  {
      
 
      Cost = PlayerPrefs.GetFloat("newcostmod");
  }
  public void Update()
  {
      CostT.text = "Cost: " + Cost.ToString("F0");
 
      PlayerPrefs.SetFloat("newcostmod", Cost[]);
 
  }
 
               }
@tp16art7 Doesnt work, tried alot of stuff with list but didnt work
They're trying to store an array of floats as a single float. Pretty sure this is nonsense.
@Bonfire-Boy it didnt work tried a lot of different things with lists. do you maybe know another way?
If you want to store information specific to an item in PlayerPrefs, then clearly it needs to have a key that's specific to the item. That's probably your starting point. Ins$$anonymous$$d of
 PlayerPrefs.SetFloat("newcostmod", Cost);
 
                    You're looking for something like
 PlayerPrefs.SetFloat("newcostmod_" + item.uniqueID, Cost);
 
                    But the way you've set things up that may not be possible without a fair bit of work.