Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by Shnayzr · Jan 28, 2015 at 07:13 PM · c#mobilemobile devices

how to know the time passed since the player closed the game?

Hello

i wanna make a game for mobile devices that has some time dependent things.

for example to kill this monster you have to wait 30 minutes.

how can i do it in a way so the player cant cheat and change the iphone time?

Comment
Add comment · Show 12
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 meat5000 ♦ · Jan 28, 2015 at 07:17 PM 0
Share

You would need to draw on an external source of time, usually a server.

avatar image Shnayzr · Jan 28, 2015 at 07:19 PM 0
Share

the game will be offline. is there any other way?

avatar image Mmmpies · Jan 28, 2015 at 07:29 PM 0
Share

I think what @meat5000 means is record the time when you want to start the wait then, when the game opens again you can check the time again.

Or if you just want to record 30 $$anonymous$$utes of actual game time, as in when the game's open, then set a float to = 1800 when the 30 $$anonymous$$utes starts and reduce by Time.deltaTime each frame until you get back to 0.

Either way save what the variables are when you exit the game and load them again when it starts.

avatar image Shnayzr · Jan 28, 2015 at 07:37 PM 0
Share

aha, so i save the the float in PlayerPrefs when he quit the game, and call it back when opens the game

so i use: OnApplicationQuit() but does that work on android and ios?

avatar image Superrodan · Jan 28, 2015 at 10:17 PM 1
Share

There is no way to do that offline as far as I know.

The only options I know of are connect to a server that definitely has the correct time, to let them cheat, or to make it so they have to be playing the entire 30 $$anonymous$$utes.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Firedan1176 · Jan 29, 2015 at 03:44 AM

You could use the function OnApplicationQuit() to save the time into the player's prefs folder (possibly as a float). When the game is started up again, you can take the current time and subtract the previous time.

Example: Exited previously at 10:00.00 PM, 1-28-15 > 20:00.00. You could then convert that to a float (from years to seconds) such as: 152801100000. If you logged back on at 8:00.00 AM 1-29-15 (next morning), it would be 152901080000. Now the only problem is if you forget to add an extra 0 (8 would be 08) for double-digits. Then you could subtract the prev. from the current, convert it to a string, parse/split it, then read that as time from last logged on. Alternatively, you could have it formatted as a string with dashes in between each "type" (days/months/seconds). It would then be easier to parse with String.Split since you could pass it the dash.

If you need more explanation, I'd be glad to provide.

Comment
Add comment · Show 2 · 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 fafase · Jan 29, 2015 at 04:52 AM 0
Share

The problem is not how to save the value but how to prevent cheating.

There is no way offline to prevent cheating.

But you can screw the cheating player in some way. Some players (including me) may change the clock, get in the game, collect the extra and then get out and set the clock back before returning in the game. Those are the players that want to cheat while keeping the device on time. While returning, you can check if the 30 $$anonymous$$ have passed and would we be before the recorded time. Then you fine them by removing a large amount of consumables. Angry Birds Transformers does that for instance.

avatar image Firedan1176 · Jan 31, 2015 at 01:45 AM 0
Share

Well there's really no way to prevent cheating. So unless you use some way of storing it, there's really no way to prevent cheating unless using encryption. But even that is possible to break. If your game can connect to the internet, then you could use that as an advantage. Ping some server to save the Server's time, and ping it again the next time they log on. They cannot change the server's time.

avatar image
0

Answer by Naphier · Jan 29, 2015 at 10:32 AM

 public static double DateTimeToUnixTimestamp(DateTime dateTime)
     {
         return (dateTime - new DateTime(1970, 1, 1)).TotalSeconds;
     }

Use DateTime.UtcNow as the parameter then you have a nice UTC unix timestamp to work from. Store that in an encrypted file. You could do this every minute with little overhead.

fafase has the right idea on punishing cheaters.

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 fafase · Jan 29, 2015 at 10:39 AM 0
Share

This will return the device time. So you can modify it.

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

27 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Game will not load scene on MOBILE, but work fine on PC 0 Answers

How to open mobile file browsers 1 Answer

My assets size is 12MB but the game size is 66MB on iphone.. why? 3 Answers


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