The best way that I have done it is by doing simple checks on your variables.
For instance lets say you have a health variable. You have it between 0-100. One simple check you can do is if its over 100 then they’ve messed with it.
Another way would be to make 2 variables one called health one called tmpHealth and make tmpHealth always 20 points higher than normal health. Then always make sure health is 20 less than tmpHealth. And if not they’ve messed with it. Simple checks like that can do what you want.
EDIT:
You can also just detect if cheat engine is running on the computer using this:
foreach (Process pro in Process.GetProcesses())
{
if (pro.ProcessName.ToLower().Contains("cheat") && pro.ProcessName.ToLower().Contains("engine"))
{
//Cheat engine is running!
}
}
Then you can either do Application.Quit() or do pro.Kill() to force close cheat engine. You should do this a few times while the program is running to make sure they dont start it after they start your game.
I think its good to note though that if its a singleplayer game it doesnt really matter if they hack it because its only effecting them. If its multiplayer then there is much more you can do to prevent this some of the methods even involve streaming your entire DLL to the server for validation.(Which only takes 1-2 seconds)
EDIT2:
Getting the hash of a DLL is simple. Then its just a matter of sending it to the server and having the server get the hash as well. Then the server verifies if the hashes match. You’re going to want to hash the ‘Assembly-CSharp.dll’ file that Unity3D makes for every game(Found in _Data/Managed/Assembly-CSharp.dll)