如何防止同时点击两个按钮或者根本上就禁止多点触碰

同标题,谁能给个详细的说明,网上好多,也有给代码的,但是不知道改哪

const { ccclass, property } = cc._decorator;

@ccclass
export default class Helloworld extends cc.Component {

  static touchBtn: Map<string, cc.Button> = new Map();
  static touchTime = 0;

  onLoad() {
        cc.Button.prototype["_onTouchBegan"] = function (event) {
            if (!this.interactable || !this.enabledInHierarchy||Date.now()-Helloworld.touchTime<200) return;
            Helloworld.touchBtn.set(this.uuid, this);
            Helloworld.touchTime = Date.now();
            this._pressed = true;
            this._updateState();
            event.stopPropagation();
        }
        cc.Button.prototype["_onTouchEnded"] = function (event) {
            if (!this.interactable || !this.enabledInHierarchy) return;
            if (this._pressed) {
                cc.Component.EventHandler.emitEvents(this.clickEvents, event);
                this.node.emit('click', this);
                Helloworld.touchBtn.forEach(btn => btn["_pressed"] = false);
                Helloworld.touchBtn.clear();
            }
            this._pressed = false;
            this._updateState();
            event.stopPropagation();
        }
  }

}

可以参考一下 随便找个地方执行下onLoad里面代码就行

1赞

嗯,谢谢,我也参考了网上一段代码,搞定了