D
D
deeda2021-02-18 21:11:45
C++ / C#
deeda, 2021-02-18 21:11:45

How to save a purchase in Unity?

I tried to do something, but it gives an error with a parenthesis. I have been sitting for the second evening and I don’t see normal solutions, so I got here, thanks in advance.

Here is the error:

IqIwpggE3uU.jpg?size=1474x218&quality=96&proxy=1&sign=2f021599826817158dad9986eaf8004c&type=album

Here is the code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BuyButton : MonoBehaviour
    
    
{
    public GameObject CostW;


    public void BuyWinter()
    {
    
        if (Score.scoreAmount >= 30) ;
        {
            if (PlayerPrefs.HasKey(CostWin, 1)) ;
            {
                if (PlayerPrefs.GetInt(buy) == 0) ;
                {
                    Score.scoreAmount -= 30;
                    PlayerPrefs.SetInt("coins", Score.scoreAmount);
                    CostW.SetActive(false);
                    PlayerPrefs.SetInt("buy", 1);
                }
            }

            else
            {
                Score.scoreAmount -= 30;
                PlayerPrefs.SetInt("coins", Score.scoreAmount);
                CostW.SetActive(false);
                PlayerPrefs.SetInt("buy", 1);
            }
           
        }
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuriy Vorobyov, 2021-02-18
@YuriyVorobyov1333

Why after each condition ";" ?
Remove them:

if (Score.scoreAmount >= 30) 
{
  if (PlayerPrefs.HasKey(CostWin, 1)) 
  {
    if (PlayerPrefs.GetInt(buy) == 0) 
    {
      Score.scoreAmount -= 30;
      PlayerPrefs.SetInt("coins", Score.scoreAmount);
      CostW.SetActive(false);
      PlayerPrefs.SetInt("buy", 1);
    }
  }

  else
  {
    Score.scoreAmount -= 30;
    PlayerPrefs.SetInt("coins", Score.scoreAmount);
    CostW.SetActive(false);
    PlayerPrefs.SetInt("buy", 1);
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question