答案 0 :(得分:2)
您可以使用Input.GetMouseButton
(在按下鼠标按钮时返回true)和计时器。仅当Input.GetMouseButton
返回true并且timer
超过一定时间并使用Input.GetMouseButtonDown
(在按下鼠标按钮的帧上返回true)时,您的代码才会被触发当前时间。代码将如下所示:
不好。我将Time.time
转换为int使其与秒更相似,但是您只需删除(int)
即可将其删除,它将恢复为浮点型。
float timer;
float timeLimit;
public float waitTime = 1; //amount of seconds that user will have to wait before code is executed
if(Input.GetMouseButtonDown(0)) timeLimit = (int)(Time.time) + waitTime; //called only once
if(Input.GetMouseButton(0)){ //called while lmb is held down
timer = (int)(Time.time);
if(timer >= timeLimit){
//Your code here
}
}