我为团结写了这个简单的反速黑客,在理论和实践中它确实(有点)有效。但是如果游戏是alt + tabbed或者最小化,甚至有时甚至是无处不在,代码认为时间已经改变了。我假设它与时滞有关?无论如何,这是脚本:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class AntiHack : MonoBehaviour {
public static float systemTime = 0F;
public static float timer = 0F;
public static bool kickPlayer = false;
public float tolerance = 1.1f;
int resetTime = 0;
// UI Canvas
public Canvas antihack_Canvas;
void Start()
{
systemTime = System.DateTime.Now.Second;
timer = System.DateTime.Now.Second;
}
void Update()
{
if (systemTime == 10F || systemTime == 50F)
{
timer = System.DateTime.Now.Second;
resetTime = 0;
}
systemTime = System.DateTime.Now.Second;
timer += Time.deltaTime;
float result = timer - systemTime;
if (result < 0 )
{
result = result * -1;
}
if (result > tolerance && kickPlayer == true && systemTime > 10F)
{
KickPlayer();
}
if (result > 60 + tolerance && systemTime < 10F && kickPlayer == true)
{
KickPlayer();
}
}
//If player got caught do this
void KickPlayer()
{
Application.LoadLevel ("antiHackScreen");
}
public static void RestartTimer(bool kick)
{
timer = System.DateTime.Now.Second;
kickPlayer = kick;
}
}
我正在启动关卡时使用它:
public class restartTimer : MonoBehaviour {
// Use this for initialization
void Start () {
AntiHack.RestartTimer (true);
}
}
任何帮助将不胜感激!谢谢!