Search Unity

Problem with creating a character shop.

Discussion in 'Scripting' started by CyborgCity, May 25, 2020.

  1. CyborgCity

    CyborgCity

    Joined:
    Apr 18, 2020
    Posts:
    1
    Hi, I am creating my first game in unity which contains a character shop. I want to implement a buy button to change the value of my coins but cant seem to do so. Help would be much appreciated.
    My code which is attached to my button:-

    {

    public int SpentCoins = 10;
    // Start is called before the first frame update
    void Start()
    {

    }

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

    }

    public void Buy1stCharacter()
    {
    PlayerPrefs.GetInt("TotalCoins");
    PlayerPrefs.SetInt("TotalCoins", PlayerPrefs.GetInt("TotalCoins") - SpentCoins);
    GetComponent<TotalCoinsDisplay>().TotalCoins.text = PlayerPrefs.GetInt("TotalCoins").ToString();
    }