Question: Time from Server to prevent hacks?

I want to make a system as in Clash of Clans or other building games in wich building something takes for example several hours. Is there a way that i can get the Time information from a server. Getting the information from the device is unsecure, because people can just change it in their phone settings. Or is there another way to prevent this cheat?
sorry for the bad english and thank you for your help! :stuck_out_tongue:

Is there a way that i can get the Time information from a server.

Yes but that depends on the server implementation and that’s out of the scope of the app you build with Unity. The server is a completely different entity from the game you make with Unity.

To get server time you could implement your own server, coding it from scratch (If you are new to this type of project I wouldn’t recommend it) or you could choose from several companies that provide this kind of service, many of them have free options to get you started, one I have experience with and I think is somewhat easy to handle (doesn’t mean you won’t have to do a lot of reasearch) is Playfab, they set up the server for you and provide a plugin for Unity so you can easily start doing server calls for interacting with tons of stuff, like inventory, logging, game economy, etc. For instance, getting server time is as easy as calling the PlayFabClientAPI.GetTime(); method, (passing the parameters that it needs) and you get server time just like that.

About cheat prevention. To really prevent cheating you should avoid doing important game logic in your client, by this I mean that on online games, clients should never contain code that calculate their money, or health, or whatever resource, that’s the server’s domain. Clients should only be able to request stuff to the server and that’s about it, something like:

Client: “Hey server please shoot a bullet for me”

Server: “No, you don’t have ammo” or “sure, I’ll spawn the bullet for you and make sure that everyone playing sees it”

Even if you get the current time from the server, if you use that time to do some local game logic, a malicious user can still do memory editing and change the value that you sent him, or if you save it to a local file the user could modify said file, an experienced hacker could even decompile your client and create a modified version, hence you should keep game logic in your server.