想要达到的功能就是任何场景添加的按钮组件点击的时候都有一个默认的音效,不用重复给按钮绑定事件,然后特殊的按钮可以更换音效。论坛里面搜了很多看得一知半解,求大神帮忙。
cc.Button.prototype.touchEndClone = cc.Button.prototype._onTouchEnded;
cc.Button.prototype._soundOn = true;
cc.Button.prototype.setSoundEffect = function (on) {
this._soundOn = on;
};
cc.Button.prototype._onTouchEnded = function (event) {
if (this.interactable && this.enabledInHierarchy && this._pressed && this._soundOn == true) {
// cc.log(“cc.Button click”);
//播放通用按钮音效
}
this.touchEndClone(event);
}
不想使用通用音效的按钮,设置setSoundEffect(false)
这个要写在哪里 为什么我写下来 一堆报错