• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by nenad96 · Sep 03, 2017 at 01:08 AM · script.date

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);
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image nenad96 · Sep 03, 2017 at 08:08 PM 0
Share

Thanks alot :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

69 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Script for auto-dated changing scene 0 Answers

joint braking problem 0 Answers

Camera follow script doesn't follow player, not sure what I'm missing. 0 Answers

My unity scrpits keeps resetting to the defualt values and i dont seem to know what the issue is 1 Answer

What wrong with my code here?? i want to create a timer with my object move it will start timer but my timer is not moving.... 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges