Answer the question
In order to leave comments, you need to log in
Unity C# Player prefs does not contain a definition for ''?
I want to save and unload variables in the game, but the following error occurs
Unity C# Player prefs does not contain a definition for ''?
Here is the code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Clicker : MonoBehaviour
{
[SerializeField] int money;
public GameObject b1;
public GameObject b2;
public GameObject b3;
public GameObject b4;
public int bonusplus = 2;
public int bonusplus2 = 7;
public Text moneyText;
public int bonus = 1;
public int autoclickbonus2 = 0;
private void Update()
{
moneyText.text = money.ToString();
SaveGame();
}
public void SaveGame()
{
PlayerPrefs.bonusplus("bonusplus", bonusplus);
PlayerPrefs.bonusplus2("bonusplus2", bonusplus2);
PlayerPrefs.bonus("bonus", bonus);
PlayerPrefs.money("money", money);
PlayerPrefs.autoclickbonus21("autoclickbonus2", autoclickbonus2);
PlayerPrefs.Save();
Debug.Log("Game data saved!");
}
public void LoadGame()
{
bonusplus = PlayerPrefs.GetInt("bonusplus");
bonusplus2 = PlayerPrefs.GetInt("bonusplus2");
bonus = PlayerPrefs.GetInt("bonus");
autoclickbonus2 = PlayerPrefs.GetInt("autoclickbonus2");
money = PlayerPrefs.GetInt("money");
Debug.Log("Game data loaded!");
}
private void Start()
{
LoadGame();
}
public void ToShop()
{
SceneManager.LoadScene(1);
}
public void Return()
{
SceneManager.LoadScene(0);
}
public void ButtonClick()
{
StartCoroutine(Click());
PlayerPrefs.SetInt("money,", money);
}
public void Buy()
{
if (money >= 300)
{
bonus += bonusplus;
money -= 300;
b1.SetActive(false);
}
else
{
Debug.Log("Not enough money");
}
}
public void Buy2()
{
if (money >= 900)
{
b2.SetActive(false);
bonus += bonusplus2;
money -= 900;
}
else
{
Debug.Log("Not enough money");
}
}
public void Buy3()
{
if (money >= 3000)
{
b3.SetActive(false);
StartCoroutine(IdleFarm());
money -= 3000;
}
else
{
Debug.Log("Not enough money");
}
}
public void Buy4()
{
if (money >= 4000)
{
b4.SetActive(false);
autoclickbonus2 += 4;
money -= 4000;
}
else
{
Debug.Log("Not enough money");
}
}
IEnumerator IdleFarm()
{
yield return new WaitForSeconds(1);
money += autoclickbonus2;
Debug.Log(money);
StartCoroutine(IdleFarm());
}
IEnumerator Click()
{
money += bonus;
yield return new WaitForSeconds(1.5f);
}
}
Answer the question
In order to leave comments, you need to log in
I don’t remember that in PlayerPrefs you could write like this
PlayerPrefs.bonusplus("bonusplus", bonusplus);
PlayerPrefs.bonusplus2("bonusplus2", bonusplus2);
PlayerPrefs.bonus("bonus", bonus);
PlayerPrefs.money("money", money);
PlayerPrefs.autoclickbonus21("autoclickbonus2", autoclickbonus2);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question