Answer the question
In order to leave comments, you need to log in
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:
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
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 questionAsk a Question
731 491 924 answers to any question