首先感谢大佬的2.x的代码,鄙人只不过是将其转成了3.x:https://blog.csdn.net/qq135595696/article/details/121939938
代码如下:
@ccclass('noClickmore')
export class noClickmore extends Component {
private ClickTime: number = 0;
private ClickMinTime: number = 0;
ButtonFunc() {
//防止按钮多次连续点击
let nowTime = new Date().getTime();
// console.log(nowTime - this.ClickTime)
if (nowTime - this.ClickTime > this.ClickMinTime) {
//do something
}
this.ClickTime = nowTime;
}
start() {
this.ClickTime = new Date().getTime();//按钮点击时间
this.ClickMinTime = 300;//按钮最小点击间隔时间,可自定义
}
update(deltaTime: number) {
}
}
然后挂在相应的button上就可以了。