Skip to main content

双击加速

using UnityEngine;
using System.Collections;
public class cs: MonoBehaviour {
public int dblclick_time; //记录时间差
public System.DateTime currentTime1=new System.DateTime();
public int w1; //用来加速的值
void Start () {
w1=1;
}

// Update is called once per frame
void Update () {
if(Input.GetKey(KeyCode.W))
{
transform.Translate(Vector3.forward * (5+w1)*Time.deltaTime, Space.Self);
}
if(Input.GetKey(KeyCode.S))
{
transform.Translate(Vector3.forward * -(5+w1)*Time.deltaTime, Space.Self);
}
if(Input.GetKey(KeyCode.A))
{
transform.Translate(Vector3.right * -(5+w1)*Time.deltaTime, Space.Self);
}
if(Input.GetKey(KeyCode.D))
{
transform.Translate(Vector3.right* (5+w1)*Time.deltaTime, Space.Self);
}

if(Input.GetKeyDown(KeyCode.W)||Input.GetKeyDown(KeyCode.S)||Input.GetKeyDown(KeyCode.A)||Input.GetKeyDown(KeyCode.D))
{
w1=1;
currentTime1=System.DateTime.Now; //保存按下按钮时候的时间
dblclick_time++;
if(dblclick_time<2&&dblclick_time>0)
{
w1=20;
}
}
System.DateTime currentTime=new System.DateTime();
currentTime=System.DateTime.Now; //系统当前时间
dblclick_time=(currentTime.Second-currentTime1.Second);
}
}