Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 /
  • Help Room /
avatar image
0
Question by WillG5677 · Jul 01, 2016 at 01:54 PM · mobiletimerenergy

Using a timer for regenerating player energy

I'm implementing player energy that regenerates over time for a mobile game. I'm using DateTime to calculate the real time elapsed even when the game is closed, and I'm checking in Update to see if enough time has passed to add energy. It would probably be more optimal to use a timer that increments the energy every few minutes. How can I do such a thing in Unity, if possible? Being able to query the timer for elapsed/remaining time would be nice.

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

Answer by andrew_2992 · Jul 01, 2016 at 08:04 PM

It looks like youre relying on local information too much.. If you want to make it simple and dont care about people cheating then just save a file to disk using something like this ... ProfileClassType ProfileClassTypeInstance; BinaryFormatter binform = new BinaryFormatter (); FileStream file = File.Create (Application.persistentDataPath + "/LocalProfile.dat"); binform.Serialize (file, PofileClassTypeInstance); file.Close (); in the ProfileCLassType class, have a date time. update it as the player plays at acceptable intervals and then when they close it, you can load the file using a similar code later. Check 'data persistence unity'.

After you've crafted your class to save the data for the time when they were last using it, and loaded that file, you'll just want to simply subtract time and then evaluate the amount to see how much energies you wanna give em.

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 andrew_2992 · Jul 01, 2016 at 08:07 PM 0
Share

Just wanted to mention too, if you do want to do this more safely... and about the same effort as well, you can contact a server. this can be a free php server you have or a cheap paid one, either or. also you can use cgi asp.net whatever you want as long as you use an http connection. For that check out the wwwform class in unity. Its basically a web browser for unity except the web page will come back as data ins$$anonymous$$d of being formatted into a nice page like our browsers do.

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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Merging two projects into one 0 Answers

Mobile joystick OnPointerUp causes error 1 Answer

Mobile Build laggy? 0 Answers

Terrain creation for android 1 Answer

Cardboard VR: "LookWalk" works in Unity, but not when I build & run to a mobile phone 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