- Home /
DateTime daily bonus script works in editor but doesn't in build
Hi, I want to build a simple daily bonus system. It's the first scene when you launch the game. It is also the only script in the scene. I store DateTime as a string, after i convert it toBinary(I've seen this approach on the forums). The problem is that it works fine in editor(panel shows once per day), when I build it to my phone it shows there every time the scene is active. UI texts which I use to print out the possible prizes are stuck on 'New Text'. Because I print out the text very early in the code I suspect the bug is above where I extract the date from memory. Thanks for help :) public GameObject panel; public Image[] imageArray; public GameObject panel; int bonuslvl; public int[] prizeArray; public Text[] textArray; // Use this for initialization void Awake() { long lastAccess; DateTime lastAccessDate;
if (PlayerPrefs.HasKey("lastrundate"))
{
lastAccess = Convert.ToInt64(PlayerPrefs.GetString("lastrundate"));
lastAccessDate = DateTime.FromBinary(poslednjipristup);
}
else
lastAccessDate = new DateTime(0);
for (int i = 0; i < 5; i++)
textArray[i].text = prizeArray[i].ToString();
if (PlayerPrefs.GetInt("firstrun") == 0)//don-t want to show the ad first time user launches the game
{
panel.SetActive(false);
PlayerPrefs.SetInt("firstrun", 1);
}
else if(lastAccessDate.Day == DateTime.Now.Day)
{
panel.SetActive(false);
}
else
{
if ((DateTime.Now - lastAccessDate).TotalDays < 2)
{
bonuslvl = PlayerPrefs.GetInt("bonuslvl");
if(bonuslvl < 4)
bonuslvl++;
}
else
bonuslvl = 0;
PlayerPrefs.SetInt("bonuslvl", bonuslvl);
}
PlayerPrefs.SetString("lastrundate", DateTime.Now.ToBinary().ToString());
for (int i = 0; i <= bonuslvl; i++)
imageArray[i].color= new Color(0.5f, 0.5f, 0.5f);
Answer by merpheus · Sep 03, 2017 at 04:07 PM
please try to change your .net api compatibility level from .net 2.0 subset to .net 2.0
Your answer
Follow this Question
Related Questions
Script for auto-dated changing scene 0 Answers
How can I make my player stay in the directions i have assigned to it? 0 Answers
Recursive function that allows me to do stuff in the meantime 3 Answers
How do i change the text color on GUI.Label ? 1 Answer
How do I place sprites with my script and a 2D array? 2 Answers