As already mentioned in the title, the playerprefs on Android do not work, but it does work in the Unity Editor.
My script looks like this:
using UnityEngine;
public class Save : MonoBehaviour
{
public Clicker clicker;
public Rps rps;
public Ads ads;
public UnrewardedAds unrewardedAds;
public OfflineIncome offlineIncome;
public Items items;
public Items items1;
/*public Items items2;
public Items items3;
public Items items4;
public Items items5;
public Items items6;*/
public Items Clickitem;
public Items Offlineitem;
public bool FirstStart = true;
private void OnEnable()
{
if(PlayerPrefs.HasKey("FirstStart") == false)
{
FirstGameStart();
PlayerPrefs.SetInt("FirsStart", 1);
PlayerPrefs.Save();
offlineIncome.OfflinePanel.SetActive(false);
Debug.Log("First Stats set");
}
}
public void FirstGameStart()
{
PlayerPrefs.SetFloat("Radiation", 0);
PlayerPrefs.SetFloat("PerClick", 1);
PlayerPrefs.SetFloat("PerClickBefore", 1);
PlayerPrefs.SetInt("TapCount", 0);
PlayerPrefs.SetInt("TotalClicks", 0);
PlayerPrefs.SetFloat("TotalSpent", 0);
PlayerPrefs.SetFloat("TotalEarned", 0);
//items
PlayerPrefs.SetInt("Cost", 100);
PlayerPrefs.SetInt("Cost1", 500);
PlayerPrefs.SetInt("ClickItemCost", 12500);
PlayerPrefs.SetInt("OfflineItemCost", 25000);
PlayerPrefs.SetInt("InBesitz", 0);
PlayerPrefs.SetInt("InBesitz1", 0);
PlayerPrefs.SetInt("ClickItemInBesitz", 0);
PlayerPrefs.SetInt("OfflineItemInBesitz", 0);
PlayerPrefs.SetFloat("Income", 0);
PlayerPrefs.SetFloat("Income1", 0);
PlayerPrefs.SetFloat("OfflineIncome", 1);
//Rps
PlayerPrefs.SetFloat("RadiationPerSecond", rps.RadiationPerSecond);
//Ads
PlayerPrefs.SetFloat("BoostTimer", ads.BoostTimer);
PlayerPrefs.SetInt("PlayedAds", ads.PlayedAds);
//UnrewardedAds
PlayerPrefs.SetFloat("TimeToShow", unrewardedAds.TimeToShow);
Debug.Log("FirstStats Set");
}
private void Start()
{
//clicker
clicker.Radiation = PlayerPrefs.GetFloat("Radiation");
clicker.PerClick = PlayerPrefs.GetFloat("PerClick");
clicker.PerClickBefore = PlayerPrefs.GetFloat("PerClickBefore");
clicker.TapCount = PlayerPrefs.GetInt("TapCount");
clicker.TotalClicks = PlayerPrefs.GetInt("TotalClicks");
clicker.TotalSpent = PlayerPrefs.GetFloat("TotalSpent");
clicker.TotalEarned = PlayerPrefs.GetFloat("TotalEarned");
//items
items.Cost = PlayerPrefs.GetInt("Cost");
items1.Cost = PlayerPrefs.GetInt("Cost1");
Clickitem.Cost = PlayerPrefs.GetInt("ClickItemCost");
Offlineitem.Cost = PlayerPrefs.GetInt("OfflineItemCost");
items.InBesitz = PlayerPrefs.GetInt("InBesitz");
items1.InBesitz = PlayerPrefs.GetInt("InBesitz1");
Clickitem.InBesitz = PlayerPrefs.GetInt("ClickItemInBesitz");
Offlineitem.InBesitz = PlayerPrefs.GetInt("OfflineItemInBesitz");
items.income = PlayerPrefs.GetFloat("Income");
items1.income = PlayerPrefs.GetFloat("Income1");
Offlineitem.OfflineIncome = PlayerPrefs.GetFloat("OfflineIncome");
//Rps
rps.RadiationPerSecond = PlayerPrefs.GetFloat("RadiationPerSecond");
//Ads
ads.BoostTimer = PlayerPrefs.GetFloat("BoostTimer");
ads.PlayedAds = PlayerPrefs.GetInt("PlayedAds");
ads.MultiplierActive = (PlayerPrefs.GetInt("MultiplierActive") != 0);
//UnrewardedAds
unrewardedAds.TimeToShow = PlayerPrefs.GetFloat("TimeToShow");
}
private void OnApplicationQuit()
{
//clicker
PlayerPrefs.SetFloat("Radiation", clicker.Radiation);
PlayerPrefs.SetFloat("PerClick", clicker.PerClick);
PlayerPrefs.SetFloat("PerClickBefore", clicker.PerClickBefore);
PlayerPrefs.SetInt("TapCount", clicker.TapCount);
PlayerPrefs.SetInt("TotalClicks", clicker.TotalClicks);
PlayerPrefs.SetFloat("TotalSpent", clicker.TotalSpent);
PlayerPrefs.SetFloat("TotalEarned", clicker.TotalEarned);
//items
PlayerPrefs.SetInt("Cost", items.Cost);
PlayerPrefs.SetInt("Cost1", items1.Cost);
PlayerPrefs.SetInt("ClickItemCost", Clickitem.Cost);
PlayerPrefs.SetInt("OfflineItemCost", Offlineitem.Cost);
PlayerPrefs.SetInt("InBesitz", items.InBesitz);
PlayerPrefs.SetInt("InBesitz1", items1.InBesitz);
PlayerPrefs.SetInt("ClickItemInBesitz", Clickitem.InBesitz);
PlayerPrefs.SetInt("OfflineItemInBesitz", Offlineitem.InBesitz);
PlayerPrefs.SetFloat("Income", items.income);
PlayerPrefs.SetFloat("Income1", items1.income);
PlayerPrefs.SetFloat("OfflineIncome", Offlineitem.OfflineIncome);
//Rps
PlayerPrefs.SetFloat("RadiationPerSecond", rps.RadiationPerSecond);
//Ads
PlayerPrefs.SetFloat("BoostTimer", ads.BoostTimer);
PlayerPrefs.SetInt("PlayedAds", ads.PlayedAds);
PlayerPrefs.SetInt("MultiplierActive", (ads.MultiplierActive ? 1 : 0));
//UnrewardedAds
PlayerPrefs.SetFloat("TimeToShow", unrewardedAds.TimeToShow);
PlayerPrefs.SetInt("FirstStart", (FirstStart ? 1 : 0));
PlayerPrefs.Save();
}
private void OnDisable()
{
PlayerPrefs.Save();
}
private void OnApplicationPause(bool pause)
{
PlayerPrefs.Save();
}
}
And here is another script in which it also does not work:
public void OnEnable()
{
OfflinePanel.SetActive(true);
currentTime = System.DateTime.Now;
long temp = Convert.ToInt64(PlayerPrefs.GetString("sysString"));
endTime = DateTime.FromBinary(temp);
Debug.Log("Old time: " + endTime);
TimeSpan difference = currentTime.Subtract(endTime);
string TimeText = string.Format("{0:D2}:{1:D2}:{2:D2}:{3:D2}", difference.Days, difference.Hours, difference.Minutes, difference.Seconds);
Debug.Log("Difference: " + difference);
double seconds = difference.TotalSeconds;
Debug.Log(seconds);
if (seconds >= MaxOfflineTime)
{
OfflineEarned = MaxOfflineTime * OfflineItem.OfflineMultiplier * rps.RadiationPerSecond;
}
else if (seconds < MaxOfflineTime)
{
OfflineEarned = (float)seconds * (rps.RadiationPerSecond * OfflineItem.OfflineIncome);
}
OfflineEarnedText.text = OfflineEarned.ToString("F1") + " Radiation";
AwayForText.text = TimeText;
}
private void OnDisable()
{
PlayerPrefs.SetString("sysString", System.DateTime.Now.ToBinary().ToString());
Debug.Log("Saving this time: " + System.DateTime.Now);
}
}
↧