I wanted to create a simple clicker on Android.But during creation, I ran into a problem with PlayerPrefs, which served to save the values of variables.The bottom line is this: I created variables to maintain the loading level of the element using if, but the error “it is impossible to implicitly convert the void type to the Int type” is also output using float.Please help me.Here is the full script code:
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.PlayerLoop;
using UnityEngine.UI;
public class click : MonoBehaviour
{
[SerializeField] private float money;
[SerializeField]private Text moneyText;
[SerializeField] private float moneyUp = 0.1f;
[SerializeField] private int moneyCount = 0;
public void Start()
{
if (PlayerPrefs.HasKey("money"))
{
money = PlayerPrefs.GetFloat("money");
}
}
public void BuyUpdate()
{
moneyCount = 0;
if (money >= 10)
{
money -= 10;
moneyCount += 1;
}
moneyCount = PlayerPrefs.SetInt("moneyCount", moneyCount);
money = PlayerPrefs.SetFloat("money2", money);
PlayerPrefs.Save();
}
public void MoneyClicker()
{
money += moneyUp;
PlayerPrefs.SetFloat("money", money);
PlayerPrefs.Save();
}
public void FixedUpdate()
{
if (money == 0.1f)
{
moneyText.text = 0.1f + "";
}
else
{
moneyText.text = money.ToString();
}
money = (float)Math.Round((float)money, 1);
}
public void Up()
{
if (PlayerPrefs.HasKey("money2"))
{
PlayerPrefs.GetFloat("money2");
}
if (PlayerPrefs.HasKey("moneyCount"))
{
PlayerPrefs.GetInt("moneyCount");
}
}
}
New contributor
Kola20000512 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.